ExporterMetadata.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. using System;
  2. using System.Reflection;
  3. using System.Collections.Generic;
  4. using System.Runtime.Serialization;
  5. using System.IO;
  6. using BabylonExport.Entities;
  7. using UnityEngine;
  8. using UnityEditor;
  9. using Object = UnityEngine.Object;
  10. namespace Unity3D2Babylon
  11. {
  12. #region Unity Components
  13. [DataContract]
  14. public class UnityScriptFile
  15. {
  16. [DataMember]
  17. public int order;
  18. [DataMember]
  19. public string name;
  20. [DataMember]
  21. public string script;
  22. }
  23. [DataContract]
  24. public class UnityFlareSystem
  25. {
  26. [DataMember]
  27. public string name;
  28. [DataMember]
  29. public string emitterId;
  30. [DataMember]
  31. public int borderLimit;
  32. [DataMember]
  33. public UnityFlareItem[] lensFlares;
  34. }
  35. [DataContract]
  36. public class UnityFlareItem
  37. {
  38. [DataMember]
  39. public float size;
  40. [DataMember]
  41. public float position;
  42. [DataMember]
  43. public float[] color;
  44. [DataMember]
  45. public string textureName;
  46. }
  47. [DataContract]
  48. public class UnityBabylonColor
  49. {
  50. [DataMember]
  51. public float r;
  52. [DataMember]
  53. public float g;
  54. [DataMember]
  55. public float b;
  56. [DataMember]
  57. public float a;
  58. }
  59. [DataContract]
  60. public class UnityBablylonVector2
  61. {
  62. [DataMember]
  63. public float x;
  64. [DataMember]
  65. public float y;
  66. }
  67. [DataContract]
  68. public class UnityBablylonVector3
  69. {
  70. [DataMember]
  71. public float x;
  72. [DataMember]
  73. public float y;
  74. [DataMember]
  75. public float z;
  76. }
  77. [DataContract]
  78. public class UnityBablylonVector4
  79. {
  80. [DataMember]
  81. public float x;
  82. [DataMember]
  83. public float y;
  84. [DataMember]
  85. public float z;
  86. [DataMember]
  87. public float w;
  88. }
  89. [DataContract]
  90. public class UnityScriptComponent
  91. {
  92. [DataMember]
  93. public int order;
  94. [DataMember]
  95. public string name;
  96. [DataMember]
  97. public string klass;
  98. [DataMember]
  99. public bool update;
  100. [DataMember]
  101. public bool controller;
  102. [DataMember]
  103. public Dictionary<string, object> properties;
  104. [DataMember]
  105. public object instance;
  106. [DataMember]
  107. public object tag;
  108. public UnityScriptComponent()
  109. {
  110. this.order = 0;
  111. this.name = String.Empty;
  112. this.klass = String.Empty;
  113. this.update = false;
  114. this.controller = false;
  115. this.properties = new Dictionary<string, object>();
  116. this.instance = null;
  117. this.tag = null;
  118. }
  119. }
  120. #endregion
  121. #region Read Only Attribute
  122. public class ReadOnlyAttribute : PropertyAttribute { }
  123. [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
  124. public class ReadOnlyDrawer : PropertyDrawer
  125. {
  126. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  127. {
  128. return EditorGUI.GetPropertyHeight(property, label, true);
  129. }
  130. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  131. {
  132. GUI.enabled = false;
  133. EditorGUI.PropertyField(position, property, label, true);
  134. GUI.enabled = true;
  135. }
  136. }
  137. #endregion
  138. }
  139. namespace UnityEditor
  140. {
  141. [System.Serializable]
  142. public class EmbeddedAsset
  143. {
  144. public BabylonTextEncoding encoding = BabylonTextEncoding.RawBytes;
  145. public TextAsset textAsset;
  146. }
  147. [System.Serializable]
  148. public class SceneMetaData
  149. {
  150. public bool api;
  151. public Dictionary<string, object> properties;
  152. public List<string> bakedMaterials;
  153. public SceneMetaData()
  154. {
  155. this.api = true;
  156. this.properties = new Dictionary<string, object>();
  157. this.bakedMaterials = new List<string>();
  158. }
  159. }
  160. [System.Serializable]
  161. public class UnityMetaData
  162. {
  163. public bool api;
  164. public string type;
  165. public string objectName;
  166. public string objectId;
  167. public string tagName;
  168. public int layerIndex;
  169. public string layerName;
  170. public int areaIndex;
  171. public object navAgent;
  172. public object meshLink;
  173. public object meshObstacle;
  174. public List<object> components;
  175. public Dictionary<string, object> properties;
  176. public UnityMetaData()
  177. {
  178. this.api = true;
  179. this.type = "Unity";
  180. this.objectName = String.Empty;
  181. this.objectId = String.Empty;
  182. this.tagName = String.Empty;
  183. this.layerIndex = -1;
  184. this.layerName = String.Empty;
  185. this.areaIndex = -1;
  186. this.navAgent = null;
  187. this.meshLink = null;
  188. this.meshObstacle = null;
  189. this.components = new List<object>();
  190. this.properties = new Dictionary<string, object>();
  191. }
  192. }
  193. [System.Serializable]
  194. public sealed class UnityLensFlareItem
  195. {
  196. public float size;
  197. public float position;
  198. public Color color;
  199. public Texture2D texture;
  200. }
  201. [System.Serializable]
  202. public class BabylonSceneOptions
  203. {
  204. public bool autoClear = true;
  205. public Color ambientColor = Color.clear;
  206. public Vector3 defaultGravity = new Vector3(0, -0.9f, 0);
  207. public Vector3 cameraEllipsoid = new Vector3(0.5f, 0.85f, 0.5f);
  208. public BabylonNavigationMesh navigationMesh = BabylonNavigationMesh.EnableNavigation;
  209. public bool particleSystems = true;
  210. public bool lensFlareSystems = true;
  211. public bool autoDrawInterface = true;
  212. public BabylonGuiMode userInterfaceMode = BabylonGuiMode.None;
  213. public EmbeddedAsset graphicUserInterface = null;
  214. }
  215. [System.Serializable]
  216. public class BabylonSoundOptions
  217. {
  218. public float volume = 1;
  219. public float playbackRate = 1;
  220. public bool autoplay = false;
  221. public bool loop = false;
  222. public int soundTrackId = -1;
  223. public bool spatialSound = false;
  224. public Vector3 position = new Vector3(0, 0, 0);
  225. public float refDistance = 1;
  226. public float rolloffFactor = 1;
  227. public float maxDistance = 100;
  228. public string distanceModel = "linear";
  229. public string panningModel = "equalpower";
  230. public bool isDirectional = false;
  231. public float coneInnerAngle = 360;
  232. public float coneOuterAngle = 360;
  233. public float coneOuterGain = 0;
  234. public Vector3 directionToMesh = new Vector3(1, 0, 0);
  235. }
  236. [System.Serializable]
  237. public class BabylonLightOptions
  238. {
  239. public BabylonAmbientLighting lightMode = BabylonAmbientLighting.UnityAmbientLighting;
  240. [Range(0.0f, 10.0f)]
  241. public float lightLevel = 1;
  242. public Color specularColor = Color.black;
  243. }
  244. [System.Serializable]
  245. public class BabylonSkyboxOptions
  246. {
  247. public bool exportSkybox = true;
  248. public BabylonTextureExport textureFile = BabylonTextureExport.AlwaysExport;
  249. public Color albedoColor = Color.white;
  250. public Color reflectivityColor = Color.white;
  251. [Range(0.0f, 5.0f)]
  252. public float lightIntensity = 1;
  253. [Range(0.0f, 5.0f)]
  254. public float microSurface = 1;
  255. [Range(0.0f, 5.0f)]
  256. public float cameraExposure = 1;
  257. [Range(0.0f, 5.0f)]
  258. public float cameraContrast = 1;
  259. [Range(0.0f, 5.0f)]
  260. public float directIntensity = 1;
  261. [Range(0.0f, 5.0f)]
  262. public float emissiveIntensity = 1;
  263. [Range(0.0f, 5.0f)]
  264. public float specularIntensity = 1;
  265. [Range(0.0f, 5.0f)]
  266. public float environmentIntensity = 1;
  267. }
  268. [System.Serializable]
  269. public class BabylonManifestOptions
  270. {
  271. public bool exportManifest = true;
  272. public int manifestVersion = 1;
  273. public bool storeSceneOffline = false;
  274. public bool storeTextureOffline = false;
  275. }
  276. public enum BabylonImageFormat
  277. {
  278. JPEG = 0,
  279. PNG = 1
  280. }
  281. public enum BabylonFogMode
  282. {
  283. None = 0,
  284. Exponential = 1,
  285. FastExponential = 2,
  286. Linear = 3
  287. }
  288. public enum BabylonGuiMode
  289. {
  290. None = 0,
  291. Html = 1
  292. }
  293. public enum BabylonTickOptions
  294. {
  295. EnableTick = 0,
  296. DisableTick = 1
  297. }
  298. public enum BabylonTextEncoding
  299. {
  300. RawBytes = 0,
  301. EncodedText = 1
  302. }
  303. public enum BabylonLightmapMode
  304. {
  305. ShadowBaking = 0,
  306. FullLightBaking = 1
  307. }
  308. public enum BabylonShadowOptions
  309. {
  310. Baked = 0,
  311. Realtime = 1
  312. }
  313. public enum BabylonLightmapBaking
  314. {
  315. Disabled = 0,
  316. Enabled = 1
  317. }
  318. public enum BabylonParticleBlend
  319. {
  320. OneOne = 0,
  321. Standard = 1
  322. }
  323. public enum BabylonTextureExport
  324. {
  325. AlwaysExport = 0,
  326. IfNotExists = 1
  327. }
  328. public enum BabylonPhysicsEngine
  329. {
  330. Cannon = 0,
  331. Oimo = 1
  332. }
  333. public enum BabylonProgramSection
  334. {
  335. Babylon = 0,
  336. Vertex = 1,
  337. Fragment = 2
  338. }
  339. public enum BabylonPhysicsImposter
  340. {
  341. None = 0,
  342. Sphere = 1,
  343. Box = 2,
  344. Plane = 3,
  345. Mesh = 4,
  346. Cylinder = 7,
  347. Particle = 8,
  348. HeightMap = 9
  349. }
  350. public enum BabylonAmbientLighting
  351. {
  352. NoAmbientLighting = 0,
  353. UnityAmbientLighting = 1
  354. }
  355. public enum BabylonNavigationMesh
  356. {
  357. DisableNavigation = 0,
  358. EnableNavigation = 1
  359. }
  360. public enum BabylonUpdateOptions
  361. {
  362. StableProduction = 0,
  363. PreviewRelease = 1,
  364. }
  365. public enum BabylonLightingFilter
  366. {
  367. NoFilter = 0,
  368. PoissonSampling = 1,
  369. VarianceShadowMap = 2,
  370. BlurVarianceShadowMap = 3,
  371. SoftPoissonSampling = 4
  372. }
  373. public class BabylonTerrainData
  374. {
  375. public Vector3[] vertices;
  376. public Vector3[] normals;
  377. public Vector2[] uvs;
  378. public int[] triangles;
  379. }
  380. public enum BabylonTerrainFormat
  381. {
  382. Triangles = 0
  383. }
  384. public enum BabylonTerrainResolution
  385. {
  386. FullResolution = 0,
  387. HighResolution = 1,
  388. MediumResolution = 2,
  389. LowResolution = 3,
  390. VeryLowResolution = 4
  391. }
  392. public enum BabylonColliderDetail
  393. {
  394. FullResolution = 0,
  395. HighResolution = 1,
  396. MediumResolution = 2,
  397. LowResolution = 3,
  398. VeryLowResolution = 4,
  399. MinimumResolution = 5
  400. }
  401. public enum BabylonPreviewWindow
  402. {
  403. OpenDefaultBrowser = 0,
  404. AttachUnityBrowser = 1
  405. }
  406. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  407. public sealed class BabylonClassAttribute : Attribute { }
  408. [AttributeUsage(AttributeTargets.Field, Inherited = false)]
  409. public sealed class BabylonPropertyAttribute : PropertyAttribute { }
  410. public abstract class BabylonScriptComponent : MonoBehaviour
  411. {
  412. [Unity3D2Babylon.ReadOnly]
  413. public string babylonClass;
  414. public BabylonTickOptions updateOption;
  415. protected BabylonScriptComponent()
  416. {
  417. this.babylonClass = "BABYLON.ScriptComponent";
  418. this.updateOption = BabylonTickOptions.EnableTick;
  419. }
  420. public virtual void OnExportProperties(ref Unity3D2Babylon.ExportationOptions exportOptions, ref GameObject unityGameObject, ref Dictionary<string, object> propertyBag, string outputPath) { }
  421. }
  422. public abstract class BabylonSceneController : BabylonScriptComponent
  423. {
  424. public BabylonSceneOptions sceneOptions;
  425. public BabylonSkyboxOptions skyboxOptions;
  426. public BabylonLightOptions lightingOptions;
  427. public BabylonManifestOptions manifestOptions;
  428. protected BabylonSceneController()
  429. {
  430. this.babylonClass = "BABYLON.SceneController";
  431. this.updateOption = BabylonTickOptions.EnableTick;
  432. }
  433. public virtual void OnExportGameObject(ref Unity3D2Babylon.ExportationOptions exportOptions, ref GameObject unityGameObject, ref UnityMetaData metaData, ref BabylonScene sceneBuilder, string outputPath) { }
  434. }
  435. }