This commit is contained in:
2025-11-13 17:40:28 +08:00
parent 962ab49609
commit 10156da245
5503 changed files with 805282 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
using Unity.XR.PXR;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.Interaction.Toolkit;
public class PXRSample_SpatialAnchor : MonoBehaviour
{
[HideInInspector]
public ulong anchorHandle;
[SerializeField]
private Text anchorID;
[SerializeField]
private GameObject savedIcon;
[SerializeField]
private GameObject uiCanvas;
[SerializeField] private Button btnPersist;
[SerializeField] private Button btnDestroyAnchor;
[SerializeField] private Button btnDeleteAnchor;
private void Awake()
{
//uiCanvas.SetActive(false);
uiCanvas.SetActive(true);
uiCanvas.GetComponent<Canvas>().worldCamera = Camera.main;
btnPersist.onClick.AddListener(OnBtnPressedPersist);
btnDestroyAnchor.onClick.AddListener(OnBtnPressedDestroy);
btnDeleteAnchor.onClick.AddListener(OnBtnPressedUnPersist);
}
protected void OnEnable()
{
}
protected void OnDisable()
{
}
private void Start()
{
}
private void Update()
{
if (uiCanvas.activeSelf)
{
uiCanvas.transform.LookAt(new Vector3(uiCanvas.transform.position.x * 2 - Camera.main.transform.position.x, uiCanvas.transform.position.y * 2 - Camera.main.transform.position.y, uiCanvas.transform.position.z * 2 - Camera.main.transform.position.z), Vector3.up);
}
}
private void LateUpdate()
{
var result = PXR_MixedReality.LocateAnchor(anchorHandle, out var position, out var rotation);
if (result == PxrResult.SUCCESS)
{
transform.position = position;
transform.rotation = rotation;
}
else
{
PXRSample_SpatialAnchorManager.Instance.SetLogInfo("LocateSpatialAnchor:" + result.ToString());
}
}
private async void OnBtnPressedPersist()
{
var result = await PXR_MixedReality.PersistSpatialAnchorAsync(anchorHandle);
PXRSample_SpatialAnchorManager.Instance.SetLogInfo("PersistSpatialAnchorAsync:" + result.ToString());
if (result == PxrResult.SUCCESS)
{
ShowSaveIcon();
}
}
private void OnBtnPressedDestroy()
{
PXRSample_SpatialAnchorManager.Instance.DestroySpatialAnchor(anchorHandle);
}
private async void OnBtnPressedUnPersist()
{
var result = await PXR_MixedReality.UnPersistSpatialAnchorAsync(anchorHandle);
PXRSample_SpatialAnchorManager.Instance.SetLogInfo("UnPersistSpatialAnchorAsync:" + result.ToString());
if (result == PxrResult.SUCCESS)
{
OnBtnPressedDestroy();
}
}
public void SetAnchorHandle(ulong handle)
{
anchorHandle = handle;
anchorID.text = "ID: " + anchorHandle;
}
public void ShowSaveIcon()
{
savedIcon.SetActive(true);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da98fba3f19feaf4c8a0e0bdd00191b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,198 @@
using System.Collections.Generic;
using Unity.XR.PXR;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR;
public class PXRSample_SpatialAnchorManager : MonoBehaviour
{
private static PXRSample_SpatialAnchorManager instance = null;
public static PXRSample_SpatialAnchorManager Instance
{
get
{
if (instance == null)
{
instance = FindObjectOfType<PXRSample_SpatialAnchorManager>();
}
return instance;
}
}
public GameObject anchorPrefab;
private bool isCreateAnchorMode = false;
public Dictionary<ulong, PXRSample_SpatialAnchor> anchorList = new Dictionary<ulong, PXRSample_SpatialAnchor>();
public Dictionary<ulong, ulong> persistTaskList = new Dictionary<ulong, ulong>();
public Dictionary<ulong, ulong> unPersistTaskList = new Dictionary<ulong, ulong>();
private InputDevice rightController;
public GameObject anchorPreview;
[SerializeField] private GameObject menuPanel;
[SerializeField] private Button btnCreateAnchor;
[SerializeField] private Button btnLoadAnchors;
private bool btnAClick = false;
private bool aLock = false;
private bool btnAState = false;
private bool gripButton = false;
public Text tipsText;
private int maxLogCount = 5;
private Queue<string> logQueue = new Queue<string>();
void Start()
{
PXR_Manager.EnableVideoSeeThrough = true;
StartSpatialAnchorProvider();
btnCreateAnchor.onClick.AddListener(OnBtnPressedCreateAnchor);
btnLoadAnchors.onClick.AddListener(OnBtnPressedLoadAllAnchors);
btnCreateAnchor.gameObject.SetActive(true);
btnLoadAnchors.gameObject.SetActive(true);
rightController = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
}
private async void StartSpatialAnchorProvider()
{
var result = await PXR_MixedReality.StartSenseDataProvider(PxrSenseDataProviderType.SpatialAnchor);
SetLogInfo("StartSenseDataProvider:" + result);
}
void OnEnable()
{
PXR_Manager.SpatialAnchorDataUpdated += SpatialAnchorDataUpdated;
}
void OnDisable()
{
PXR_Manager.SpatialAnchorDataUpdated -= SpatialAnchorDataUpdated;
}
// Update is called once per frame
void Update()
{
ProcessKeyEvent();
menuPanel.SetActive(gripButton);
if (isCreateAnchorMode && btnAClick)
{
CreateSpatialAnchor(anchorPreview.transform);
}
}
private void ProcessKeyEvent()
{
rightController.TryGetFeatureValue(CommonUsages.primaryButton, out btnAState);
if (btnAState && !aLock)
{
btnAClick = true;
aLock = true;
}
else
{
btnAClick = false;
}
if (!btnAState)
{
btnAClick = false;
aLock = false;
}
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand).TryGetFeatureValue(CommonUsages.gripButton, out gripButton);
}
private void SpatialAnchorDataUpdated()
{
SetLogInfo("SpatialAnchorDataUpdated:");
OnBtnPressedLoadAllAnchors();
}
private void OnBtnPressedCreateAnchor()
{
isCreateAnchorMode = !isCreateAnchorMode;
if (isCreateAnchorMode)
{
btnCreateAnchor.transform.Find("Text").GetComponent<Text>().text = "CancelCreate";
anchorPreview.SetActive(true);
}
else
{
btnCreateAnchor.transform.Find("Text").GetComponent<Text>().text = "CreateAnchor";
anchorPreview.SetActive(false);
}
}
private async void OnBtnPressedLoadAllAnchors()
{
var result = await PXR_MixedReality.QuerySpatialAnchorAsync();
SetLogInfo("LoadSpatialAnchorAsync:" + result.result.ToString());
if (result.result == PxrResult.SUCCESS)
{
foreach (var key in result.anchorHandleList)
{
if (!anchorList.ContainsKey(key))
{
GameObject anchorObject = Instantiate(anchorPrefab);
PXRSample_SpatialAnchor anchor = anchorObject.GetComponent<PXRSample_SpatialAnchor>();
anchor.SetAnchorHandle(key);
PXR_MixedReality.LocateAnchor(key, out var position, out var orientation);
anchor.transform.position = position;
anchor.transform.rotation = orientation;
anchorList.Add(key, anchor);
anchorList[key].ShowSaveIcon();
}
}
}
}
private async void CreateSpatialAnchor(Transform transform)
{
var result = await PXR_MixedReality.CreateSpatialAnchorAsync(transform.position, transform.rotation);
SetLogInfo("CreateSpatialAnchorAsync:" + result.ToString());
if (result.result == PxrResult.SUCCESS)
{
GameObject anchorObject = Instantiate(anchorPrefab);
PXRSample_SpatialAnchor anchor = anchorObject.GetComponent<PXRSample_SpatialAnchor>();
if (anchor == null)
{
anchor = anchorObject.AddComponent<PXRSample_SpatialAnchor>();
}
anchor.SetAnchorHandle(result.anchorHandle);
anchorList.Add(result.anchorHandle, anchor);
var result1 = PXR_MixedReality.GetAnchorUuid(result.anchorHandle, out var uuid);
SetLogInfo("GetUuid:" + result1.ToString() + " " + (result.uuid.Equals(uuid)) + "Uuid:" + uuid);
}
}
public void DestroySpatialAnchor(ulong anchorHandle)
{
var result = PXR_MixedReality.DestroyAnchor(anchorHandle);
SetLogInfo("DestroySpatialAnchor:" + result.ToString());
if (result == PxrResult.SUCCESS)
{
if (anchorList.ContainsKey(anchorHandle))
{
Destroy(anchorList[anchorHandle].gameObject);
anchorList.Remove(anchorHandle);
}
}
}
public void SetLogInfo(string log)
{
if (logQueue.Count >= maxLogCount)
{
logQueue.Dequeue();
}
logQueue.Enqueue(log);
tipsText.text = string.Join("\n", logQueue.ToArray());
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3fed85861409e824a953639daefaacd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,185 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.XR.PXR;
using UnityEngine.UI;
using System;
#if PICO_OPENXR_SDK
using Unity.XR.OpenXR.Features.PICOSupport;
#endif
public class PXR_BodyTrackingBlock : MonoBehaviour
{
public Transform skeletonJoints;
public bool showCube = true;
public float zDistance = 0;
private bool supportedBT = false;
private bool updateBT = true;
private BodyTrackingGetDataInfo bdi = new BodyTrackingGetDataInfo();
private BodyTrackingData bd = new BodyTrackingData();
private Transform[] boneMapping = new Transform[(int)BodyTrackerRole.ROLE_NUM];
BodyTrackingStatus bs = new BodyTrackingStatus();
bool istracking = false;
// Start is called before the first frame update
void Start()
{
skeletonJoints.transform.localPosition += new Vector3(0, 0, zDistance);
InitializeSkeletonJoints();
StartBodyTracking();
}
// Update is called once per frame
void Update()
{
#if UNITY_ANDROID
// Update bodytracking pose.
if (updateBT)
{
#if PICO_OPENXR_SDK
BodyTrackingFeature.GetBodyTrackingState(ref istracking, ref bs);
#else
PXR_MotionTracking.GetBodyTrackingState(ref istracking, ref bs);
#endif
// If not calibrated, invoked system motion tracker app for calibration.
if (bs.stateCode != BodyTrackingStatusCode.BT_VALID)
{
return;
}
// Get the position and orientation data of each body node.
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)
{
for (int i = 0; i < (int)BodyTrackerRole.ROLE_NUM; i++)
{
var bone = boneMapping[i];
if (bone != null)
{
bone.transform.localPosition = new Vector3((float)bd.roleDatas[i].localPose.PosX, (float)bd.roleDatas[i].localPose.PosY,
(float)bd.roleDatas[i].localPose.PosZ);
bone.transform.localRotation = 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);
}
}
}
}
#endif
}
public void StartBodyTracking()
{
// Query whether the current device supports human body tracking.
#if PICO_OPENXR_SDK
supportedBT = BodyTrackingFeature.IsBodyTrackingSupported();
#else
PXR_MotionTracking.GetBodyTrackingSupported(ref supportedBT);
#endif
if (!supportedBT)
{
return;
}
BodyTrackingBoneLength bones = new BodyTrackingBoneLength();
// Start BodyTracking
#if PICO_OPENXR_SDK
BodyTrackingFeature.StartBodyTracking(BodyJointSet.BODY_JOINT_SET_BODY_FULL_START, bones);
BodyTrackingFeature.GetBodyTrackingState(ref istracking, ref bs);
#else
PXR_MotionTracking.StartBodyTracking(BodyJointSet.BODY_JOINT_SET_BODY_FULL_START, bones);
PXR_MotionTracking.GetBodyTrackingState(ref istracking, ref bs);
#endif
// 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
}
}
skeletonJoints.gameObject.SetActive(true);
updateBT = true;
}
private void OnDestroy()
{
#if PICO_OPENXR_SDK
int ret = BodyTrackingFeature.StopBodyTracking();
#else
int ret = PXR_MotionTracking.StopBodyTracking();
#endif
updateBT = false;
}
public void InitializeSkeletonJoints()
{
Queue<Transform> nodes = new Queue<Transform>();
nodes.Enqueue(skeletonJoints);
while (nodes.Count > 0)
{
Transform next = nodes.Dequeue();
for (int i = 0; i < next.childCount; ++i)
{
nodes.Enqueue(next.GetChild(i));
}
ProcessJoint(next);
}
}
void ProcessJoint(Transform joint)
{
int index = GetJointIndex(joint.name);
if (index >= 0 && index < (int)BodyTrackerRole.ROLE_NUM)
{
boneMapping[index] = joint;
Transform cubeT = joint.Find("Cube");
if (cubeT)
{
cubeT.gameObject.SetActive(showCube);
}
}
else
{
Debug.LogWarning($"{joint.name} was not found.");
}
}
// Returns the integer value corresponding to the JointIndices enum value
// passed in as a string.
int GetJointIndex(string jointName)
{
BodyTrackerRole val;
if (Enum.TryParse(jointName, out val))
{
return (int)val;
}
return -1;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 097fbbaba53a01d42936fa80fff2d8ee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,257 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.XR.PXR;
using UnityEngine.UI;
using System;
using static UnityEngine.UI.Dropdown;
#if PICO_OPENXR_SDK
using Unity.XR.OpenXR.Features.PICOSupport;
#endif
public class PXR_BodyTrackingDebugBlock : MonoBehaviour
{
public Transform skeletonJoints;
public bool showCube = true;
public float zDistance = 0;
public Dropdown dropdown;
public Text changeJointTittle;
private bool supportedBT = false;
private bool updateBT = true;
private Transform changeJointT;
private BodyTrackingGetDataInfo bdi = new BodyTrackingGetDataInfo();
private BodyTrackingData bd = new BodyTrackingData();
private Transform[] boneMapping = new Transform[(int)BodyTrackerRole.ROLE_NUM];
private Transform[] targetMapping = new Transform[(int)BodyTrackerRole.ROLE_NUM];
BodyTrackingStatus bs = new BodyTrackingStatus();
bool istracking = false;
// Start is called before the first frame update
void Start()
{
dropdown.ClearOptions();
skeletonJoints.transform.localPosition += new Vector3(0, 0, zDistance);
InitializeSkeletonJoints();
StartBodyTracking();
dropdown.RefreshShownValue();
dropdown.onValueChanged.AddListener(delegate
{
DropdownValueChanged(dropdown);
});
}
// Update is called once per frame
void Update()
{
#if UNITY_ANDROID
// Update bodytracking pose.
if (updateBT)
{
#if PICO_OPENXR_SDK
BodyTrackingFeature.GetBodyTrackingState(ref istracking, ref bs);
#else
PXR_MotionTracking.GetBodyTrackingState(ref istracking, ref bs);
#endif
// If not calibrated, invoked system motion tracker app for calibration.
if (bs.stateCode!=BodyTrackingStatusCode.BT_VALID)
{
return;
}
// Get the position and orientation data of each body node.
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)
{
for (int i = 0; i < (int)BodyTrackerRole.ROLE_NUM; i++)
{
var bone = boneMapping[i];
if (bone != null)
{
bone.transform.localPosition = new Vector3((float)bd.roleDatas[i].localPose.PosX, (float)bd.roleDatas[i].localPose.PosY, (float)bd.roleDatas[i].localPose.PosZ);
bone.transform.localRotation = 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);
}
}
}
}
#endif
}
public void StartBodyTracking()
{
// Query whether the current device supports human body tracking.
#if PICO_OPENXR_SDK
supportedBT= BodyTrackingFeature.IsBodyTrackingSupported();
#else
PXR_MotionTracking.GetBodyTrackingSupported(ref supportedBT);
#endif
if (!supportedBT)
{
return;
}
BodyTrackingBoneLength bones = new BodyTrackingBoneLength();
// Start BodyTracking
#if PICO_OPENXR_SDK
BodyTrackingFeature.StartBodyTracking(BodyJointSet.BODY_JOINT_SET_BODY_FULL_START, bones);
BodyTrackingFeature.GetBodyTrackingState(ref istracking, ref bs);
#else
PXR_MotionTracking.StartBodyTracking(BodyJointSet.BODY_JOINT_SET_BODY_FULL_START, bones);
PXR_MotionTracking.GetBodyTrackingState(ref istracking, ref bs);
#endif
// 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
}
}
skeletonJoints.gameObject.SetActive(true);
updateBT = true;
}
private void OnDestroy()
{
#if PICO_OPENXR_SDK
int ret = BodyTrackingFeature.StopBodyTracking();
#else
int ret = PXR_MotionTracking.StopBodyTracking();
#endif
updateBT = false;
}
public void InitializeSkeletonJoints()
{
Queue<Transform> nodes = new Queue<Transform>();
nodes.Enqueue(skeletonJoints);
while (nodes.Count > 0)
{
Transform next = nodes.Dequeue();
for (int i = 0; i < next.childCount; ++i)
{
nodes.Enqueue(next.GetChild(i));
}
ProcessJoint(next);
}
}
void ProcessJoint(Transform joint)
{
int index = GetJointIndex(joint.name);
if (index >= 0 && index < (int)BodyTrackerRole.ROLE_NUM)
{
boneMapping[index] = joint;
Transform cubeT = joint.Find("Cube");
if (cubeT)
{
cubeT.gameObject.SetActive(showCube);
}
OptionData optionData = new OptionData();
optionData.text = joint.name;
dropdown.options.Add(optionData);
if (index == 0)
{
changeJointT = cubeT;
var cubeRenderer = changeJointT.GetComponent<Renderer>();
cubeRenderer.material.SetColor("_Color", Color.green);
if (changeJointTittle)
{
changeJointTittle.text = "Joint Rotation : " + joint.name;
}
}
}
else
{
Debug.LogWarning($"{joint.name} was not found.");
}
}
// Returns the integer value corresponding to the JointIndices enum value
// passed in as a string.
int GetJointIndex(string jointName)
{
BodyTrackerRole val;
if (Enum.TryParse(jointName, out val))
{
return (int)val;
}
return -1;
}
void DropdownValueChanged(Dropdown change)
{
if (changeJointTittle)
{
changeJointTittle.text = "Joint Rotation : " + change.options[change.value].text;
}
foreach (var b in boneMapping)
{
changeJointT = b.Find("Cube");
var cubeRenderer = changeJointT.GetComponent<Renderer>();
cubeRenderer.material.SetColor("_Color", Color.white);
}
var bone = boneMapping[change.value];
if (bone)
{
changeJointT = bone.Find("Cube");
var cubeRenderer = changeJointT.GetComponent<Renderer>();
cubeRenderer.material.SetColor("_Color", Color.green);
}
}
public void SetRotationX(float x)
{
if (changeJointT)
{
changeJointT.localRotation = Quaternion.AngleAxis(x, Vector3.right);
}
}
public void SetRotationY(float y)
{
if (changeJointT)
{
changeJointT.localRotation = Quaternion.AngleAxis(y, Vector3.up);
}
}
public void SetRotationZ(float z)
{
if (changeJointT)
{
changeJointT.localRotation = Quaternion.AngleAxis(z, Vector3.forward);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 942b30517cab85247a53f9e13863762b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,196 @@
using System.Collections;
using System.Collections.Generic;
using Unity.XR.PXR;
using UnityEngine;
#if PICO_OPENXR_SDK
using Unity.XR.OpenXR.Features.PICOSupport;
#endif
public class PXR_CameraEffectBlock : MonoBehaviour
{
public Texture2D lutTex;
private int row = 0;
private int col = 0;
private float brightness = 0;
private float contrast = 0;
private float saturation = 0;
private PassthroughStyle passthroughStyle = new()
{
enableColorMap = true,
enableEdgeColor = true,
TextureOpacityFactor = 1.0f
};
private float r = 0;
private float g = 0;
private float b = 0;
private float a = 0;
private Color[] values;
// Start is called before the first frame update
void Start()
{
#if PICO_OPENXR_SDK
PassthroughFeature.EnableVideoSeeThrough = true;
values = new Color[PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB];
#else
PXR_Manager.EnableVideoSeeThrough = true;
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
#endif
}
// Update is called once per frame
void Update()
{
}
public void SetColortemp(float x)
{
#if PICO_OPENXR_SDK
#else
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Colortemp, x, 0);
#endif
}
public void SetBrightness(float x)
{
#if PICO_OPENXR_SDK
brightness = x;
PassthroughFeature.SetBrightnessContrastSaturation(ref passthroughStyle, brightness, contrast, saturation);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
#else
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Brightness, x, 0);
#endif
}
public void SetSaturation(float x)
{
#if PICO_OPENXR_SDK
saturation = x;
PassthroughFeature.SetBrightnessContrastSaturation(ref passthroughStyle, brightness, contrast, saturation);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
#else
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Saturation, x, 0);
#endif
}
public void SetContrast(float x)
{
#if PICO_OPENXR_SDK
contrast = x;
PassthroughFeature.SetBrightnessContrastSaturation(ref passthroughStyle, brightness, contrast, saturation);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
#else
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Contrast, x, 0);
#endif
}
public void SetLut()
{
if (lutTex)
{
#if PICO_OPENXR_SDK
#else
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
PXR_MixedReality.SetVideoSeeThroughLut(lutTex, 8, 8);
#endif
}
}
public void ClearAll()
{
#if PICO_OPENXR_SDK
passthroughStyle = new()
{
enableColorMap = true,
enableEdgeColor = true,
TextureOpacityFactor = 1.0f
};
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
#else
PXR_MixedReality.EnableVideoSeeThroughEffect(false);
#endif
}
#if PICO_OPENXR_SDK
public void MonoToMono()
{
var monOvalues = new int[PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB];
for (int i = 0; i < PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB; ++i)
{
monOvalues[i] = i;
}
PassthroughFeature.SetColorMapbyMonoToMono(ref passthroughStyle, monOvalues);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
}
public void SetEdgeColorToR(float x)
{
r = x;
SetEdgeColorRGBA();
}
public void SetEdgeColorToG(float x)
{
g = x;
SetEdgeColorRGBA();
}
public void SetEdgeColorToB(float x)
{
b = x;
SetEdgeColorRGBA();
}
public void SetEdgeColorToA(float x)
{
a = x;
SetEdgeColorRGBA();
}
public void SetEdgeColorRGBA()
{
passthroughStyle.EdgeColor = new Color(r, g, b, a);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
}
public void SetColorMapR()
{
var values = new Color[PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB];
for (int i = 0; i < PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB; ++i)
{
float colorValue = i / 255.0f;
values[i] = new Color(colorValue, 0.0f, 0.0f, 1.0f);
}
PassthroughFeature.SetColorMapbyMonoToRgba(ref passthroughStyle, values);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
}
public void SetColorMapG()
{
var values = new Color[PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB];
for (int i = 0; i < PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB; ++i)
{
float colorValue = i / 255.0f;
values[i] = new Color(0.0f, colorValue, 0.0f, 1.0f);
}
PassthroughFeature.SetColorMapbyMonoToRgba(ref passthroughStyle, values);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
}
public void SetColorMapB()
{
var values = new Color[PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB];
for (int i = 0; i < PassthroughFeature.XR_PASSTHROUGH_COLOR_MAP_MONO_SIZE_FB; ++i)
{
float colorValue = i / 255.0f;
values[i] = new Color(0.0f, 0.0f, colorValue, 1.0f);
}
PassthroughFeature.SetColorMapbyMonoToRgba(ref passthroughStyle, values);
PassthroughFeature.SetPassthroughStyle(passthroughStyle);
}
#endif
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 41e24597e86cd0642a0a2d98622a50c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
using System.Collections.Generic;
using Unity.XR.PXR;
using UnityEngine;
using UnityEngine.Rendering;
public class PXR_ObjectTrackingBlock : MonoBehaviour
{
private Transform objectTrackers;
private bool updateOT = true;
private int objectTrackersMaxNum = 3;
int DeviceCount = 1;
List<long> trackerIds = new List<long>();
// Start is called before the first frame update
void Start()
{
objectTrackers = transform;
for (int i = 0; i < objectTrackersMaxNum; i++)
{
GameObject ga = GameObject.CreatePrimitive(PrimitiveType.Cube);
ga.transform.parent = objectTrackers;
ga.transform.localScale = Vector3.one * 0f;
#if UNITY_6000_0_OR_NEWER
if (GraphicsSettings.defaultRenderPipeline != null)
#else
if (GraphicsSettings.renderPipelineAsset != null)
#endif
{
Material material = new Material(Shader.Find("Universal Render Pipeline/Lit"));
Renderer renderer = ga.GetComponent<Renderer>();
if (renderer != null)
{
renderer.sharedMaterial = material;
}
}
}
int res = -1;
#if PICO_OPENXR_SDK
#else
PXR_MotionTracking.RequestMotionTrackerCompleteAction += RequestMotionTrackerComplete;
res = PXR_MotionTracking.CheckMotionTrackerNumber(MotionTrackerNum.TWO);
#endif
if (res == 0)
{
objectTrackers.gameObject.SetActive(true);
}
}
private void RequestMotionTrackerComplete(RequestMotionTrackerCompleteEventData obj)
{
DeviceCount = (int)obj.trackerCount;
for (int i = 0; i < DeviceCount; i++)
{
trackerIds.Add(obj.trackerIds[i]);
}
updateOT = true;
}
// Update is called once per frame
void Update()
{
#if UNITY_ANDROID
for (int i = 0; i < objectTrackersMaxNum; i++)
{
var child = objectTrackers.GetChild(i);
if (child)
{
child.localScale = Vector3.zero;
}
}
// Update motiontrackers pose.
if (updateOT )
{
MotionTrackerLocation location = new MotionTrackerLocation();
for (int i = 0; i < trackerIds.Count; i++)
{
bool isValidPose = false;
int result = -1;
#if PICO_OPENXR_SDK
#else
result = PXR_MotionTracking.GetMotionTrackerLocation(trackerIds[i], ref location, ref isValidPose);
#endif
// if the return is successful
if (result == 0)
{
var child = objectTrackers.GetChild(i);
if (child)
{
child.localPosition = location.pose.Position.ToVector3();
child.localRotation = location.pose.Orientation.ToQuat();
child.localScale = Vector3.one * 0.1f;
}
}
}
}
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebf5cf49b568aa24db3dbf4a942dee24
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SliderText : MonoBehaviour
{
public Text text;
private Slider m_Slider;//Slider<65><72><EFBFBD><EFBFBD>
// Start is called before the first frame update
void Start()
{
m_Slider = GetComponent<Slider>();
m_Slider.onValueChanged.AddListener(delegate {ValueChangeCheck(); });
}
private void ValueChangeCheck()
{
text.text = m_Slider.value.ToString();
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2685195f56c9cfc4c8822476cbe32045
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: