udProject.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. namespace udSDK
  5. {
  6. public enum udProjectGeometryType {
  7. //These are the geometry types for nodes
  8. udPGT_None, //!<There is no geometry associated with this node.
  9. udPGT_Point, //!<pCoordinates is a single 3D position
  10. udPGT_MultiPoint, //!<Array of udPGT_Point, pCoordinates is an array of 3D positions.
  11. udPGT_LineString, //!<pCoordinates is an array of 3D positions forming an open line
  12. udPGT_MultiLineString, //!<Array of udPGT_LineString; pCoordinates is NULL and children will be present.
  13. udPGT_Polygon, //!<pCoordinates will be a closed linear ring (the outside), there MAY be children that are interior as pChildren udPGT_MultiLineString items, these should be counted as islands of the external ring.
  14. udPGT_MultiPolygon, //!<pCoordinates is null, children will be udPGT_Polygon (which still may have internal islands)
  15. udPGT_GeometryCollection, //!<Array of geometries; pCoordinates is NULL and children may be present of any type.
  16. udPGT_Count, //!<Total number of geometry types. Used internally but can be used as an iterator max when displaying different type modes.
  17. udPGT_Internal, //!<Used internally when calculating other types. Do not use.
  18. }
  19. public enum udProjectNodeType
  20. {
  21. /*
  22. This represents the type of data stored in the node.
  23. Note
  24. The itemtypeStr in the udProjectNode is a string version. This enum serves to simplify the reading of standard types. The the string in brackets at the end of the comment is the string.
  25. */
  26. udPNT_Custom, //!< Need to check the itemtypeStr string manually
  27. udPNT_PointCloud, //!< A Euclideon Unlimited Detail Point Cloud file ("UDS")
  28. udPNT_PointOfInterest, //!< A point, line or region describing a location of interest ("POI")
  29. udPNT_Folder, //!< A folder of other nodes ("Folder")
  30. udPNT_Media, //!< An Image, Movie, Audio file or other media object ("Media")
  31. udPNT_Viewpoint, //!< An Camera Location & Orientation ("Camera")
  32. udPNT_VisualisationSettings, //!< Visualisation settings (itensity, map height etc) ("VizSet")
  33. udPNT_I3S, //!< An Indexed 3d Scene Layer (I3S) or Scene Layer Package (SLPK) dataset ("I3S")
  34. udPNT_Water, //!< A region describing the location of a body of water ("Water")
  35. udPNT_ViewShed, //!< A point describing where to generate a view shed from ("ViewMap")
  36. udPNT_Polygon, //!< A polygon model, usually an OBJ or FBX ("Polygon")
  37. udPNT_QueryFilter, //!< A query filter to be applied to all PointCloud types in the scene ("QFilter")
  38. udPNT_Places, //!< A collection of places that can be grouped together at a distance ("Places")
  39. udPNT_HeightMeasurement, //!< A height measurement object ("MHeight")
  40. udPNT_GTFS, //!< A General Transit Feed Specification object ("GTFS")
  41. udPNT_Count //!< Total number of node types. Used internally but can be used as an iterator max when displaying different type modes.
  42. }
  43. public enum udProjectLoadSource
  44. {
  45. udProjectLoadSource_Memory, //!< The project source exists in memory; udProject_CreateInMemory, udProject_LoadFromMemory or udProject_SaveToMemory
  46. udProjectLoadSource_Server, //!< The project source exists from the server; udProject_CreateInServer, udProject_LoadFromServer or udProject_SaveToServer
  47. udProjectLoadSource_URI, //!< The project source exists from a file or URL; udProject_CreateInFile, udProject_LoadFromFile or udProject_SaveToFile
  48. udProjectLoadSource_Count //!< Total number of source types. Used internally but can be used as an iterator max when displaying different source types.
  49. }
  50. [StructLayout(LayoutKind.Sequential)]
  51. public struct udProjectNode
  52. {
  53. /*
  54. Stores the state of a node.
  55. Warning
  56. This struct is exposed to avoid having a huge API of accessor functions but it should be treated as read only with the exception of pUserData. Making changes to the internal data will cause issues syncronising data
  57. */
  58. public readonly bool isVisible;
  59. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 37)]
  60. public readonly char[] UUID; //!<Unique identifier for this node “id”.
  61. public readonly double lastUpdate; //!<The last time this node was updated in UTC.
  62. public readonly udProjectNodeType itemtype; //!<The type of this node, see udProjectNodeType for more information.
  63. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
  64. public readonly char[] itemtypeStr; //!<The string representing the type of node. If its a known type during node creation itemtype will be set to something other than udPNT_Custom.
  65. public readonly IntPtr pName; //!<Human readable name of the item.
  66. public readonly IntPtr pURI; //!<The address or filename that the resource can be found.
  67. public readonly bool hasBoundingBox; //!<Set to true if this nodes boundingBox item is filled out.
  68. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
  69. public readonly double[] boundingBox; //!<The bounds of this model, ordered as [West, South, Floor, East, North, Ceiling].
  70. public readonly udProjectGeometryType geomtype; //!<Indicates what geometry can be found in this model. See the udProjectGeometryType documentation for more information.
  71. public readonly int geomCount; //!<How many geometry items can be found on this model.
  72. public readonly IntPtr pCoordinates; //!<The positions of the geometry of this node (NULL this this node doesn’t have points). The format is [X0,Y0,Z0,…Xn,Yn,Zn].
  73. public readonly IntPtr pNextSibling; //!<This is the next item in the project (NULL if no further siblings)
  74. public readonly IntPtr pFirstChild; //!<Some types (“folder”, “collection”, “polygon”…) have children nodes, NULL if there are no children.
  75. IntPtr pUserData; //!<This is application specific user data. The application should traverse the tree to release these before releasing the udProject.
  76. public readonly IntPtr pInternalData; //!<Internal udSDK specific state for this node.
  77. }
  78. public class UDProject
  79. {
  80. IntPtr pudProject;
  81. public IntPtr pRootNode;
  82. public UDProject(string geoJSON)
  83. {
  84. if(!GlobalUDContext.isCreated)
  85. throw new Exception("Global context not loaded, cannot load project.");
  86. UnityEngine.Debug.Log("Attempting project load from memory");
  87. udError err = udProject_LoadFromMemory(GlobalUDContext.uContext.pContext, ref pudProject, geoJSON);
  88. if(err != udError.udE_Success)
  89. throw new Exception("project load failed: "+ err.ToString());
  90. pRootNode = IntPtr.Zero;
  91. udProject_GetProjectRoot(pudProject, ref pRootNode);
  92. UnityEngine.Debug.Log("Project loaded");
  93. }
  94. ~UDProject()
  95. {
  96. udProject_Release(ref pudProject);
  97. }
  98. //Create an empty, local only, instance of udProject.
  99. [DllImport(UDSDKLibrary.name)]
  100. private static extern udError udProject_CreateLocal(ref IntPtr ppProject, string pName);
  101. //Create a local only instance of udProject filled in with the contents of a GeoJSON string.
  102. [DllImport(UDSDKLibrary.name)]
  103. private static extern udError udProject_LoadFromMemory(IntPtr pContext, ref IntPtr ppProject, string pGeoJSON);
  104. //Destroy the instance of the project.
  105. [DllImport(UDSDKLibrary.name)]
  106. private static extern udError udProject_Release(ref IntPtr ppProject);
  107. //Export a project to a GeoJSON string in memory.
  108. [DllImport(UDSDKLibrary.name)]
  109. private static extern udError udProject_SaveToMemory(IntPtr pContext, IntPtr pProject, ref IntPtr ppMemory);
  110. //Get the project root node.
  111. [DllImport(UDSDKLibrary.name)]
  112. private static extern udError udProject_GetProjectRoot(IntPtr pProject, ref IntPtr ppRootNode);
  113. //Get the state of unsaved local changes
  114. [DllImport(UDSDKLibrary.name)]
  115. private static extern udError udProject_HasUnsavedChanges(IntPtr pProject);
  116. [DllImport(UDSDKLibrary.name)]
  117. private static extern string udProject_GetTypeName(udProjectNodeType itemtype);
  118. }
  119. public class UDProjectNode
  120. {
  121. public IntPtr pNode;
  122. public udProjectNode nodeData;
  123. public UDProjectNode(IntPtr nodeAddr)
  124. {
  125. pNode = nodeAddr;
  126. this.nodeData = (udProjectNode) Marshal.PtrToStructure(nodeAddr, typeof(udProjectNode));
  127. }
  128. //Create a node in a project
  129. [DllImport(UDSDKLibrary.name)]
  130. private static extern udError udProjectNode_Create(IntPtr pProject, IntPtr ppNode, ref udProjectNode pParent, string pType, string pName, string pURI, IntPtr pUserData);
  131. //Move a node to reorder within the current parent or move to a different parent.
  132. [DllImport(UDSDKLibrary.name)]
  133. private static extern udError udProjectNode_MoveChild(IntPtr pProject, ref udProjectNode pCurrentParent, ref udProjectNode pNewParent, ref udProjectNode pNode, ref udProjectNode pInsertBeforeChild);
  134. //Remove a node from the project.
  135. [DllImport(UDSDKLibrary.name)]
  136. private static extern udError udProjectNode_RemoveChild(IntPtr pProject, ref udProjectNode pParentNode, ref udProjectNode pNode);
  137. //Set the human readable name of a node.
  138. [DllImport(UDSDKLibrary.name)]
  139. private static extern udError udProjectNode_SetName(IntPtr pProject, ref udProjectNode pNode, string pNodeName);
  140. //Set the URI of a node.
  141. [DllImport(UDSDKLibrary.name)]
  142. private static extern udError udProjectNode_SetURI(IntPtr pProject, ref udProjectNode pNode, string pNodeURI);
  143. //Set the new geometry of a node.
  144. [DllImport(UDSDKLibrary.name)]
  145. private static extern udError udProjectNode_SetGeometry(IntPtr pProject, ref udProjectNode pNode, udProjectGeometryType nodeType, int geometryCount, ref double pCoordinates);
  146. //Get a metadata item of a node as an integer.
  147. [DllImport(UDSDKLibrary.name)]
  148. private static extern udError udProjectNode_GetMetadataInt(ref udProjectNode pNode, string pMetadataKey, ref Int32 pInt, Int32 defaultValue);
  149. //Set a metadata item of a node from an integer.
  150. [DllImport(UDSDKLibrary.name)]
  151. private static extern udError udProjectNode_SetMetadataInt(ref udProjectNode pNode, string pMetadataKey, Int32 iValue);
  152. //Get a metadata item of a node as an unsigned integer.
  153. [DllImport(UDSDKLibrary.name)]
  154. private static extern udError udProjectNode_GetMetadataUint(ref udProjectNode pNode, string pMetadataKey, ref UInt32 pInt, UInt32 defaultValue);
  155. //Set a metadata item of a node from an unsigned integer.
  156. [DllImport(UDSDKLibrary.name)]
  157. private static extern udError udProjectNode_SetMetadataUint(ref udProjectNode pNode, string pMetadataKey, UInt32 iValue);
  158. //Get a metadata item of a node as a 64 bit integer.
  159. [DllImport(UDSDKLibrary.name)]
  160. private static extern udError udProjectNode_GetMetadataInt64(ref udProjectNode pNode, string pMetadataKey, ref Int64 pInt64, Int64 defaultValue);
  161. //Set a metadata item of a node from a 64 bit integer.
  162. [DllImport(UDSDKLibrary.name)]
  163. private static extern udError udProjectNode_SetMetadataInt64(ref udProjectNode pNode, string pMetadataKey, Int64 i64Value);
  164. //Get a metadata item of a node as a double.
  165. [DllImport(UDSDKLibrary.name)]
  166. private static extern udError udProjectNode_GetMetadataDouble(ref udProjectNode pNode, string pMetadataKey, ref double pDouble, double defaultValue);
  167. //Set a metadata item of a node from a double.
  168. [DllImport(UDSDKLibrary.name)]
  169. private static extern udError udProjectNode_SetMetadataDouble(ref udProjectNode pNode, string pMetadataKey, double doubleValue);
  170. //Get a metadata item of a node as an boolean.
  171. [DllImport(UDSDKLibrary.name)]
  172. private static extern udError udProjectNode_GetMetadataBool(ref udProjectNode pNode, string pMetadataKey, ref bool pBool, bool defaultValue);
  173. //Set a metadata item of a node from an boolean.
  174. [DllImport(UDSDKLibrary.name)]
  175. private static extern udError udProjectNode_SetMetadataBool(ref udProjectNode pNode, string pMetadataKey, bool boolValue);
  176. //Get a metadata item of a node as a string.
  177. [DllImport(UDSDKLibrary.name)]
  178. private static extern udError udProjectNode_GetMetadataString(ref udProjectNode pNode, string pMetadataKey, ref string ppString, string pDefaultValue);
  179. //Set a metadata item of a node from a string.
  180. [DllImport(UDSDKLibrary.name)]
  181. private static extern udError udProjectNode_SetMetadataString(ref udProjectNode pNode, string pMetadataKey, string pString);
  182. //Get the standard type string name for an itemtype
  183. }
  184. }