SpatialMeshDemo.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using EZXR.Glass.SpatialMesh;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class SpatialMeshDemo : BaseGlassSDKDemo
  8. {
  9. private bool isShowSmoothedMesh = false;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. }
  14. // Update is called once per frame
  15. new void Update()
  16. {
  17. if (isShowSmoothedMesh)
  18. {
  19. SpatialMeshManager.Instance.ShowSmoothedMeshes();
  20. }
  21. else
  22. {
  23. SpatialMeshManager.Instance.ShowIncrementalMeshes();
  24. }
  25. base.Update();
  26. }
  27. public void OnBtnClick_MeshDetection(Button button) {
  28. if (SpatialMeshManager.Instance.IsMeshDetecting)
  29. {
  30. SpatialMeshManager.Instance.pauseMeshDetecting();
  31. button.GetComponentInChildren<Text>().text = "Resume\nMesh Detection";
  32. }
  33. else {
  34. SpatialMeshManager.Instance.resumeMeshDetecting();
  35. button.GetComponentInChildren<Text>().text = "Pause\nMesh Detection";
  36. }
  37. }
  38. public void OnBtnClick_ShowSmoothedMesh(Button button)
  39. {
  40. if (isShowSmoothedMesh)
  41. {//to show incremental meshes
  42. isShowSmoothedMesh = false;
  43. SpatialMeshManager.Instance.incrementalMeshVisible = true;
  44. SpatialMeshManager.Instance.smoothedMeshVisible = false;
  45. button.GetComponentInChildren<Text>().text = "To Show\nSmoothedMesh";
  46. CancelInvoke("updateSmoothMesh");
  47. }
  48. else
  49. {//to show smoothed meshes
  50. SpatialMeshManager.Instance.incrementalMeshVisible = false;
  51. SpatialMeshManager.Instance.smoothedMeshVisible = true;
  52. isShowSmoothedMesh = true;
  53. button.GetComponentInChildren<Text>().text = "To Show\nIncrementalMesh";
  54. InvokeRepeating("updateSmoothMesh", 0.01f, 2.0f);
  55. }
  56. }
  57. private void updateSmoothMesh() {
  58. if (isShowSmoothedMesh) {
  59. SpatialMeshManager.Instance.UpdateSmoothedMeshes();
  60. }
  61. }
  62. public void OnBtnClick_ExportMesh()
  63. {
  64. new Thread(() =>
  65. {
  66. SpatialMeshManager.Instance.SaveBackendSmoothedMesh();
  67. }).Start();
  68. }
  69. }