add package files

This commit is contained in:
VR164000
2023-06-15 09:52:08 +08:00
parent 06d41412be
commit a0b3b91879
382 changed files with 44971 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
{
"displayName": "Meshing Subsystem Extension",
"description": "Shows a teapot mesh generated from native mesh subsystem with physics baked in background.",
"createSeparatePackage": false
}

View File

@@ -0,0 +1,98 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8233015818774569630
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8233015818774569626}
- component: {fileID: 8233015818774569629}
- component: {fileID: 8233015818774569628}
- component: {fileID: 8233015818774569631}
m_Layer: 0
m_Name: DynamicMeshPrefab_Default
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8233015818774569626
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8233015818774569630}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &8233015818774569629
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8233015818774569630}
m_Mesh: {fileID: 0}
--- !u!23 &8233015818774569628
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8233015818774569630}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!64 &8233015818774569631
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8233015818774569630}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 0
m_CookingOptions: -1
m_Mesh: {fileID: 0}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 66ff45e19501b9d46953d454f972a44f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,98 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5489681467619248415
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5489681467619248411}
- component: {fileID: 5489681467619248412}
- component: {fileID: 5489681467619248413}
- component: {fileID: 5489681467619248414}
m_Layer: 0
m_Name: DynamicMeshPrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5489681467619248411
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5489681467619248415}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &5489681467619248412
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5489681467619248415}
m_Mesh: {fileID: 0}
--- !u!23 &5489681467619248413
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5489681467619248415}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 6ae6f0f40939f294aae5b64149c541c1, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!64 &5489681467619248414
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5489681467619248415}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 0
m_CookingOptions: -1
m_Mesh: {fileID: 0}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3ebc6439fa8ba274985db624056324df
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.XR.OpenXR.Samples.MeshingFeature
{
public class FallingSphere : MonoBehaviour
{
private Vector3 starting;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
starting = transform.position;
}
// Update is called once per frame
void FixedUpdate()
{
if (transform.position.y < -10)
{
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
rb.MovePosition(starting);
}
}
}
}

View File

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

View File

@@ -0,0 +1,290 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SubsystemsImplementation;
using UnityEngine.XR;
using UnityEngine.InputSystem;
using VIVE.SceneUnderstanding;
namespace UnityEngine.XR.OpenXR.Samples.MeshingFeature
{
public class MeshingBehaviour : MonoBehaviour
{
public GameObject emptyMeshPrefab_Default;
public GameObject emptyMeshPrefab_Occlusion;
public Material meshMat_Default;
public Material meshMat_Occlusion;
private GameObject emptyMeshPrefab;
private Material meshesMat;
public TextMesh textMesh;
public Transform target;
public bool isOcclusion = true;
private XRMeshSubsystem s_MeshSubsystem;
private List<MeshInfo> s_MeshInfos = new List<MeshInfo>();
private Dictionary<MeshId, GameObject> m_MeshIdToGo = new Dictionary<MeshId, GameObject>();
#region OpenXR feature
private MeshingTeapotFeature m_MeshingFeature;
#endregion
#region Scene compute consistency
[Header("Scene compute consistency")]
[Tooltip("Scene compute consistency can only be set before entering the play mode.")]
public XrSceneComputeConsistencyMSFT m_SceneComputeConsistency =
XrSceneComputeConsistencyMSFT.SnapshotIncompleteFast;
#endregion
#region Scene compute bound variables
[Header("Scene compute bounds")]
// Sphere bound.
public bool m_EnableSphereBound;
private bool m_PreviousEnableSphereBound = false;
// A default sphere game object.
public GameObject m_SphereBoundObject;
// Box bound.
public bool m_EnableBoxBound;
private bool m_PreviousEnableBoxBound = false;
// A default cube game object
// Box bound is enabled by default.
public GameObject m_BoxBoundObject;
// Frustum bound.
public bool m_EnableFrustumBound;
private bool m_PreviousEnableFrustumBound = false;
public Camera m_FrustumBoundCamera;
public float m_FarDistance = 2.0f;
#endregion
#region Mesh compute lod variables
[Header("Mesh compute lod")]
public XrMeshComputeLodMSFT m_MeshComputeLod =
XrMeshComputeLodMSFT.Coarse;
private XrMeshComputeLodMSFT m_PrevMeshComputeLod =
XrMeshComputeLodMSFT.Coarse;
#endregion
void Start()
{
// Set the mesh prefab to default material.
if(emptyMeshPrefab_Occlusion == null || emptyMeshPrefab_Default == null)
{
return;
}
emptyMeshPrefab = isOcclusion ? emptyMeshPrefab_Occlusion : emptyMeshPrefab_Default;
m_MeshingFeature = OpenXRSettings.Instance.GetFeature<MeshingTeapotFeature>();
if (m_MeshingFeature == null || m_MeshingFeature.enabled == false)
{
enabled = false;
return;
}
var meshSubsystems = new List<XRMeshSubsystem>();
SubsystemManager.GetInstances(meshSubsystems);
if (meshSubsystems.Count == 1)
{
s_MeshSubsystem = meshSubsystems[0];
textMesh.gameObject.SetActive(false);
}
else
{
#if UNITY_EDITOR
textMesh.text = "Failed to initialize MeshSubsystem.\nTry reloading the Unity Editor";
#else
textMesh.text = "Failed to initialize MeshSubsystem.";
#endif
enabled = false;
}
if (m_FrustumBoundCamera == null)
{
m_FrustumBoundCamera = Camera.main;
}
// Set scene compute consistency at the start.
m_MeshingFeature.SetSceneComputeConsistency(m_SceneComputeConsistency);
// Set mesh compute lod.
m_MeshingFeature.SetMeshComputeLod(m_MeshComputeLod);
}
void Update()
{
if (s_MeshSubsystem.running && s_MeshSubsystem.TryGetMeshInfos(s_MeshInfos))
{
foreach (var meshInfo in s_MeshInfos)
{
switch (meshInfo.ChangeState)
{
case MeshChangeState.Added:
case MeshChangeState.Updated:
if (!m_MeshIdToGo.TryGetValue(meshInfo.MeshId, out var go))
{
go = Instantiate(emptyMeshPrefab, target, false);
m_MeshIdToGo[meshInfo.MeshId] = go;
}
var mesh = go.GetComponent<MeshFilter>().mesh;
var col = go.GetComponent<MeshCollider>();
s_MeshSubsystem.GenerateMeshAsync(meshInfo.MeshId, mesh, col, MeshVertexAttributes.None,
result =>
{
result.Mesh.RecalculateNormals();
});
break;
case MeshChangeState.Removed:
if (m_MeshIdToGo.TryGetValue(meshInfo.MeshId, out var meshGo))
{
Destroy(meshGo);
m_MeshIdToGo.Remove(meshInfo.MeshId);
}
break;
default:
break;
}
}
}
// Read keyboard input by the Input System package.
if (Keyboard.current.sKey.wasPressedThisFrame)
{
// Toggle the sphere bound.
m_EnableSphereBound ^= true;
}
if (Keyboard.current.bKey.wasPressedThisFrame)
{
// Toggle the box bound.
m_EnableBoxBound ^= true;
}
if (Keyboard.current.fKey.wasPressedThisFrame)
{
// Toggle the frustum bound.
m_EnableFrustumBound ^= true;
}
if (Keyboard.current.numpad1Key.wasPressedThisFrame)
{
// Set mesh lod to coarse.
m_MeshComputeLod = XrMeshComputeLodMSFT.Coarse;
}
if (Keyboard.current.numpad2Key.wasPressedThisFrame)
{
// Set mesh lod to medium.
m_MeshComputeLod = XrMeshComputeLodMSFT.Medium;
}
if (Keyboard.current.numpad3Key.wasPressedThisFrame)
{
// Set mesh lod to fine.
m_MeshComputeLod = XrMeshComputeLodMSFT.Fine;
}
if (Keyboard.current.numpad4Key.wasPressedThisFrame)
{
// Set mesh lod to unlimited.
m_MeshComputeLod = XrMeshComputeLodMSFT.Unlimited;
}
if (m_MeshingFeature == null) return;
// Set scene computation sphere bound.
if (m_EnableSphereBound)
{
SetSceneComputeSphereBound();
}
else if (m_PreviousEnableSphereBound)
{
// The bound becomes disabled. Clear related data in the plugin.
m_MeshingFeature.ClearSceneComputeBounds(XrSceneBoundType.Sphere);
}
m_PreviousEnableSphereBound = m_EnableSphereBound;
// Set scene computation box bound.
if (m_EnableBoxBound)
{
SetSceneComputeOrientedBoxBound();
}
else if (m_PreviousEnableBoxBound)
{
// The bound becomes disabled. Clear related data in the plugin.
m_MeshingFeature.ClearSceneComputeBounds(XrSceneBoundType.OrientedBox);
}
m_PreviousEnableBoxBound = m_EnableBoxBound;
// Set scene computation frustum bound.
if (m_EnableFrustumBound)
{
SetSceneComputeFrustumBound();
}
else if (m_PreviousEnableFrustumBound)
{
// The bound becomes disabled. Clear related data in the plugin.
m_MeshingFeature.ClearSceneComputeBounds(XrSceneBoundType.Frustum);
}
m_PreviousEnableFrustumBound = m_EnableFrustumBound;
// Set mesh compute lod if updated.
if (m_MeshComputeLod != m_PrevMeshComputeLod)
{
m_MeshingFeature.SetMeshComputeLod(m_MeshComputeLod);
m_PrevMeshComputeLod = m_MeshComputeLod;
}
}
void SetSceneComputeSphereBound()
{
if (m_SphereBoundObject == null) return;
m_MeshingFeature.SetSceneComputeSphereBound(m_SphereBoundObject.transform.position,
0.5f * m_SphereBoundObject.transform.localScale.x); // The radius of a default sphere is 0.5f.
}
void SetSceneComputeOrientedBoxBound()
{
if (m_BoxBoundObject == null) return;
m_MeshingFeature.SetSceneComputeOrientedBoxBound(m_BoxBoundObject.transform,
m_BoxBoundObject.transform.localScale); // The widths of a default cube is 1.0f.
}
void SetSceneComputeFrustumBound()
{
var camera = m_FrustumBoundCamera;
if (camera == null) return;
var halfVerticalFieldOfView = 0.5f * camera.fieldOfView * Mathf.Deg2Rad;
var halfHorizontalFieldOfView = 0.5f * Camera.VerticalToHorizontalFieldOfView(
camera.fieldOfView, camera.aspect) * Mathf.Deg2Rad;
m_MeshingFeature.SetSceneComputeFrustumBound(camera.transform,
halfVerticalFieldOfView, -1 * halfVerticalFieldOfView,
halfHorizontalFieldOfView, -1 * halfHorizontalFieldOfView,
m_FarDistance);
// camera.farClipPlane);
}
public void SwitchMeshPrefab()
{
if(emptyMeshPrefab_Default != null && emptyMeshPrefab_Occlusion != null)
{
isOcclusion ^= true;
Debug.Log("isOcclusion: " + isOcclusion);
emptyMeshPrefab = isOcclusion ? emptyMeshPrefab_Occlusion : emptyMeshPrefab_Default;
Renderer[] allChildern = target.transform.GetComponentsInChildren<Renderer>();
foreach(Renderer child in allChildern)
{
if(isOcclusion)
{
child.material = meshMat_Occlusion;
}
else
{
child.material = meshMat_Default;
}
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d1889e247a55eae4d96baf9f3b786800
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,215 @@
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine.XR.OpenXR.Features;
#if UNITY_EDITOR
using UnityEditor.XR.OpenXR.Features;
#endif
using VIVE.SceneUnderstanding;
namespace UnityEngine.XR.OpenXR.Samples.MeshingFeature
{
/// <summary>
/// Example extension showing how to supply a mesh from native code with OpenXR SceneUnderstanding functions.
/// </summary>
#if UNITY_EDITOR
[OpenXRFeature(UiName = "Meshing Subsystem",
BuildTargetGroups = new[] { BuildTargetGroup.Standalone, BuildTargetGroup.WSA, BuildTargetGroup.Android },
Company = "HTC",
Desc = "Example extension showing how to supply a mesh from native code with OpenXR SceneUnderstanding functions.",
DocumentationLink = "https://developer.vive.com/resources/openxr/openxr-pcvr/tutorials/unity/interact-real-world-openxr-scene-understanding/",
OpenxrExtensionStrings = "",
Version = "0.0.1",
FeatureId = featureId)]
#endif
public class MeshingTeapotFeature : SceneUnderstanding_OpenXR_API
{
/// <summary>
/// The feature id string. This is used to give the feature a well known id for reference.
/// </summary>
new public const string featureId = "com.unity.openxr.feature.example.meshing";
private static List<XRMeshSubsystemDescriptor> s_MeshDescriptors =
new List<XRMeshSubsystemDescriptor>();
#region Subsystem callbacks
/// <inheritdoc />
protected override void OnSubsystemCreate ()
{
CreateSubsystem<XRMeshSubsystemDescriptor, XRMeshSubsystem>(s_MeshDescriptors, "Sample Meshing");
}
/// <inheritdoc />
protected override void OnSubsystemStart ()
{
StartSubsystem<XRMeshSubsystem>();
}
/// <inheritdoc />
protected override void OnSubsystemStop ()
{
StopSubsystem<XRMeshSubsystem>();
}
/// <inheritdoc />
protected override void OnSubsystemDestroy ()
{
DestroySubsystem<XRMeshSubsystem>();
}
#endregion
#region OpenXR callbacks
protected override void OnSessionCreate(ulong xrSession)
{
UnityEngine.Debug.Log($"OnSessionCreate({xrSession})");
m_XrSession = xrSession;
NativeApi.SetOpenXRVariables(m_XrInstance, m_XrSession,
Marshal.GetFunctionPointerForDelegate(m_XrEnumerateReferenceSpaces),
Marshal.GetFunctionPointerForDelegate(m_XrCreateReferenceSpace),
Marshal.GetFunctionPointerForDelegate(m_XrDestroySpace),
Marshal.GetFunctionPointerForDelegate(m_XrEnumerateSceneComputeFeaturesMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrCreateSceneObserverMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrDestroySceneObserverMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrCreateSceneMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrDestroySceneMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrComputeNewSceneMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrGetSceneComputeStateMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrGetSceneComponentsMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrLocateSceneComponentsMSFT),
Marshal.GetFunctionPointerForDelegate(m_XrGetSceneMeshBuffersMSFT));
systemProperties.type = XrStructureType.XR_TYPE_SYSTEM_PROPERTIES;
XrSystemPassThroughPropertiesHTC SystemPassThroughPropertiesHTC;
SystemPassThroughPropertiesHTC.type = XrStructureType.XR_TYPE_SYSTEM_PASS_THROUGH_PROPERTIES_HTC;
unsafe
{
systemProperties.next = (IntPtr)(&SystemPassThroughPropertiesHTC);
}
int res = xrGetSystemProperties(ref systemProperties);
if (res != (int)XrResult.XR_SUCCESS)
{
UnityEngine.Debug.Log("Failed to get systemproperties with error code : " + res);
}
}
protected override void OnSessionDestroy(ulong xrSession)
{
UnityEngine.Debug.Log($"OnSessionDestroy({xrSession})");
}
#endregion
#region OpenXR scene compute consistency
public void SetSceneComputeConsistency(XrSceneComputeConsistencyMSFT consistency)
{
NativeApi.SetSceneComputeConsistency(consistency);
}
#endregion
#region OpenXR scene compute bounds
public void SetSceneComputeSphereBound(Vector3 center, float radius)
{
// Convert to right-handed center.
center.z *= -1;
// Debug.Log("box, pos: " + center + ", radi: " + radius);
NativeApi.SetSceneComputeSphereBound(center, radius);
}
public void SetSceneComputeOrientedBoxBound(Transform transform, Vector3 extent)
{
// Convert to right-handed transform.
Vector4 rotation;
Vector3 position;
ConvertTransform(transform, out rotation, out position);
NativeApi.SetSceneComputeOrientedBoxBound(rotation, position, extent);
}
/// <summary>
/// Set scene computation frustum bound.
/// </summary>
/// <param name = "angleUp">The fov up angle in radian.</param>
/// <param name = "angleDown">The fov down angle in radian.</param>
/// <param name = "angleRight">The fov right angle in radian.</param>
/// <param name = "angleLeft">The fov left angle in radian.</param>
public void SetSceneComputeFrustumBound(Transform transform, float angleUp,
float angleDown, float angleRight, float angleLeft, float farDistance)
{
// Convert to right-handed transform.
Vector4 rotation;
Vector3 position;
ConvertTransform(transform, out rotation, out position);
NativeApi.SetSceneComputeFrustumBound(rotation, position, angleUp, angleDown,
angleRight, angleLeft, farDistance);
}
/// <summery>
/// Convert a Unity left-handed tranform to right-handed world-space
/// position and rotation.
/// <param name="rotation">Output right-handed quaternion rotation</param>
/// <param name="position">Output right-handed position</param>
/// </summary>
private void ConvertTransform(Transform transform, out Vector4 rotation, out Vector3 position)
{
// Get left-handed values.
position = transform.position;
float angle;
Vector3 axis;
transform.rotation.ToAngleAxis(out angle, out axis);
// Convert left-handed values to right-handed.
position.z *= -1;
angle *= -1;
axis.z *= -1;
var rotationQuaternion = Quaternion.AngleAxis(angle, axis);
rotation = Vector4.zero;
for (var i = 0; i < 4; ++i) rotation[i] = rotationQuaternion[i];
}
public void ClearSceneComputeBounds(XrSceneBoundType type)
{
NativeApi.ClearSceneComputeBounds(type);
}
#endregion
#region OpenXR mesh compute lod
public void SetMeshComputeLod(XrMeshComputeLodMSFT lod)
{
NativeApi.SetMeshComputeLod(lod);
}
#endregion
class NativeApi
{
[DllImport("MeshingFeaturePlugin")]
public static extern void SetOpenXRVariables(ulong instance, ulong session,
IntPtr PFN_XrEnumerateReferenceSpaces,
IntPtr PFN_XrCreateReferenceSpace,
IntPtr PFN_XrDestroySpace,
IntPtr PFN_XrEnumerateSceneComputeFeaturesMSFT,
IntPtr PFN_XrCreateSceneObserverMSFT,
IntPtr PFN_XrDestroySceneObserverMSFT,
IntPtr PFN_XrCreateSceneMSFT,
IntPtr PFN_XrDestroySceneMSFT,
IntPtr PFN_XrComputeNewSceneMSFT,
IntPtr PFN_XrGetSceneComputeStateMSFT,
IntPtr PFN_XrGetSceneComponentsMSFT,
IntPtr PFN_XrLocateSceneComponentsMSFT,
IntPtr PFN_XrGetSceneMeshBuffersMSFT);
[DllImport("MeshingFeaturePlugin")]
public static extern void SetSceneComputeConsistency(XrSceneComputeConsistencyMSFT consistency);
[DllImport("MeshingFeaturePlugin")]
public static extern void SetSceneComputeSphereBound(Vector3 center, float radius);
[DllImport("MeshingFeaturePlugin")]
public static extern void SetSceneComputeOrientedBoxBound(Vector4 rotation, Vector3 position, Vector3 extent);
[DllImport("MeshingFeaturePlugin")]
public static extern void SetSceneComputeFrustumBound(Vector4 rotation, Vector3 position,
float angleUp, float angleDown, float angleRight, float angleLeft, float farDistance);
[DllImport("MeshingFeaturePlugin")]
public static extern void ClearSceneComputeBounds(XrSceneBoundType type);
[DllImport("MeshingFeaturePlugin")]
public static extern void SetMeshComputeLod(XrMeshComputeLodMSFT lod);
}
}
}

View File

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

View File

@@ -0,0 +1,9 @@
# Meshing Feature Sample
Demonstrates how to author an OpenXR Feature which sets up a custom XR Meshing Subsystem.
The [XR SDK Meshing Subsystem](https://docs.unity3d.com/2020.2/Documentation/Manual/xrsdk-meshing.html) allows for one to surface procedurally-generated meshes within Unity. Within OpenXR this functionality can be exposed by using creating an `OpenXRFeature` to manage the subsystem. This sample uses a native plugin to provide a teapot mesh through a [XRMeshingSubsystem](https://docs.unity3d.com/2020.2/Documentation/ScriptReference/XR.XRMeshSubsystem.html) that is managed by an OpenXR feature.
See the [XR SDK Meshing Subsystem](https://docs.unity3d.com/2020.2/Documentation/Manual/xrsdk-meshing.html) for more information about the meshing subsystem.
See the [Unity OpenXR Documentation](https://docs.unity3d.com/Packages/com.unity.xr.openxr@latest) for more information on developing a custom feature.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 10e59aeaf5edbf141ba393c666e48031
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: