udPointCloud.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. namespace udSDK
  5. {
  6. [StructLayout(LayoutKind.Sequential)]
  7. public struct udVoxelID
  8. {
  9. public UInt64 index;
  10. public IntPtr pTrav;
  11. public IntPtr pRenderInfo;
  12. }
  13. [StructLayout(LayoutKind.Sequential)]
  14. public struct udPointCloudHeader
  15. {
  16. public double scaledRange; //!< The point cloud's range multiplied by the voxel size
  17. public double unitMeterScale; //!< The scale to apply to convert to/from metres (after scaledRange is applied to the unitCube)
  18. public uint totalLODLayers; //!< The total number of LOD layers in this octree
  19. public double convertedResolution; //!< The resolution this model was converted at
  20. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
  21. public double[] storedMatrix; //!< This matrix is the 'default' internal matrix to go from a unit cube to the full size
  22. public udAttributeSet attributes; //!< The attributes contained in this pointcloud
  23. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
  24. public double[] baseOffset; //!< The offset to the root of the pointcloud in unit cube space
  25. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
  26. public double[] pivot; //!< The pivot point of the model, in unit cube space
  27. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
  28. public double[] boundingBoxCenter; //!< The center of the bounding volume, in unit cube space
  29. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
  30. public double[] boundingBoxExtents; //!< The extents of the bounding volume, in unit cube space }
  31. }
  32. public class udPointCloud
  33. {
  34. public IntPtr pModel = IntPtr.Zero;
  35. private udContext context;
  36. public void Load(udContext context, string modelLocation, ref udPointCloudHeader header)
  37. {
  38. if (context.pContext == IntPtr.Zero)
  39. throw new Exception("Point cloud load failed: udContext is not initialised");
  40. udError error = udPointCloud_Load(context.pContext, ref pModel, modelLocation, ref header);
  41. if (error != udError.udE_Success)
  42. throw new Exception("udPointCloud.Load " +modelLocation + " failed: " + error.ToString());
  43. this.context = context;
  44. }
  45. public void Unload()
  46. {
  47. udError error = udPointCloud_Unload(ref pModel);
  48. if (error != udError.udE_Success)
  49. throw new Exception("udPointCloud.Unload failed.");
  50. }
  51. public void GetMetadata(ref string ppJSONMetadata)
  52. {
  53. udError error = udPointCloud_GetMetadata(pModel, ref ppJSONMetadata);
  54. if (error != udError.udE_Success)
  55. throw new Exception("udPointCloud.GetMetadata failed.");
  56. }
  57. public udError GetStreamingStatus()
  58. {
  59. return udPointCloud_GetStreamingStatus(this.pModel);
  60. }
  61. [DllImport(UDSDKLibrary.name)]
  62. private static extern udError udPointCloud_Load(IntPtr pContext, ref IntPtr ppModel, string modelLocation, ref udPointCloudHeader header);
  63. [DllImport(UDSDKLibrary.name)]
  64. private static extern udError udPointCloud_Unload(ref IntPtr ppModel);
  65. [DllImport(UDSDKLibrary.name)]
  66. private static extern udError udPointCloud_GetMetadata(IntPtr pModel, ref string ppJSONMetadata);
  67. [DllImport(UDSDKLibrary.name)]
  68. private static extern udError udPointCloud_GetNodeColour(IntPtr pModel, udVoxelID voxelID, IntPtr pColour);
  69. [DllImport(UDSDKLibrary.name)]
  70. private static extern udError udPointCloud_GetAttributeAddress(IntPtr pModel, udVoxelID voxelID, uint attributeOffset, ref IntPtr ppAttributeAddress);
  71. [DllImport(UDSDKLibrary.name)]
  72. private static extern udError udPointCloud_GetStreamingStatus(IntPtr pModel);
  73. }
  74. }