ExporterMetadata.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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 BabylonNavigationMesh navigationMesh = BabylonNavigationMesh.EnableNavigation;
  207. public bool particleSystems = true;
  208. public bool lensFlareSystems = true;
  209. public bool autoDrawInterface = true;
  210. public BabylonGuiMode userInterfaceMode = BabylonGuiMode.None;
  211. public EmbeddedAsset graphicUserInterface = null;
  212. }
  213. [System.Serializable]
  214. public class BabylonSoundOptions
  215. {
  216. public float volume = 1;
  217. public float playbackRate = 1;
  218. public bool autoplay = false;
  219. public bool loop = false;
  220. public int soundTrackId = -1;
  221. public bool spatialSound = false;
  222. public Vector3 position = new Vector3(0, 0, 0);
  223. public float refDistance = 1;
  224. public float rolloffFactor = 1;
  225. public float maxDistance = 100;
  226. public string distanceModel = "linear";
  227. public string panningModel = "equalpower";
  228. public bool isDirectional = false;
  229. public float coneInnerAngle = 360;
  230. public float coneOuterAngle = 360;
  231. public float coneOuterGain = 0;
  232. public Vector3 directionToMesh = new Vector3(1, 0, 0);
  233. }
  234. [System.Serializable]
  235. public class BabylonLightOptions
  236. {
  237. public BabylonAmbientLighting lightMode = BabylonAmbientLighting.UnityAmbientLighting;
  238. [Range(0.0f, 10.0f)]
  239. public float lightLevel = 1;
  240. public Color specularColor = Color.black;
  241. }
  242. [System.Serializable]
  243. public class BabylonSkyboxOptions
  244. {
  245. public bool exportSkybox = true;
  246. public BabylonTextureExport textureFile = BabylonTextureExport.AlwaysExport;
  247. public Color albedoColor = Color.white;
  248. public Color reflectivityColor = Color.white;
  249. [Range(0.0f, 5.0f)]
  250. public float lightIntensity = 1;
  251. [Range(0.0f, 5.0f)]
  252. public float microSurface = 1;
  253. [Range(0.0f, 5.0f)]
  254. public float cameraExposure = 1;
  255. [Range(0.0f, 5.0f)]
  256. public float cameraContrast = 1;
  257. [Range(0.0f, 5.0f)]
  258. public float directIntensity = 1;
  259. [Range(0.0f, 5.0f)]
  260. public float emissiveIntensity = 1;
  261. [Range(0.0f, 5.0f)]
  262. public float specularIntensity = 1;
  263. [Range(0.0f, 5.0f)]
  264. public float environmentIntensity = 1;
  265. }
  266. [System.Serializable]
  267. public class BabylonManifestOptions
  268. {
  269. public bool exportManifest = true;
  270. public int manifestVersion = 1;
  271. public bool storeSceneOffline = false;
  272. public bool storeTextureOffline = false;
  273. }
  274. public enum BabylonImageFormat
  275. {
  276. JPEG = 0,
  277. PNG = 1
  278. }
  279. public enum BabylonFogMode
  280. {
  281. None = 0,
  282. Exponential = 1,
  283. FastExponential = 2,
  284. Linear = 3
  285. }
  286. public enum BabylonGuiMode
  287. {
  288. None = 0,
  289. Html = 1
  290. }
  291. public enum BabylonTickOptions
  292. {
  293. EnableTick = 0,
  294. DisableTick = 1
  295. }
  296. public enum BabylonTextEncoding
  297. {
  298. RawBytes = 0,
  299. EncodedText = 1
  300. }
  301. public enum BabylonLightmapMode
  302. {
  303. ShadowBaking = 0,
  304. FullLightBaking = 1
  305. }
  306. public enum BabylonShadowOptions
  307. {
  308. Baked = 0,
  309. Realtime = 1
  310. }
  311. public enum BabylonLightmapBaking
  312. {
  313. Disabled = 0,
  314. Enabled = 1
  315. }
  316. public enum BabylonParticleBlend
  317. {
  318. OneOne = 0,
  319. Standard = 1
  320. }
  321. public enum BabylonTextureExport
  322. {
  323. AlwaysExport = 0,
  324. IfNotExists = 1
  325. }
  326. public enum BabylonPhysicsEngine
  327. {
  328. Cannon = 0,
  329. Oimo = 1
  330. }
  331. public enum BabylonProgramSection
  332. {
  333. Babylon = 0,
  334. Vertex = 1,
  335. Fragment = 2
  336. }
  337. public enum BabylonPhysicsImposter
  338. {
  339. None = 0,
  340. Sphere = 1,
  341. Box = 2,
  342. Plane = 3,
  343. Mesh = 4,
  344. Cylinder = 7,
  345. Particle = 8,
  346. HeightMap = 9
  347. }
  348. public enum BabylonAmbientLighting
  349. {
  350. NoAmbientLighting = 0,
  351. UnityAmbientLighting = 1
  352. }
  353. public enum BabylonNavigationMesh
  354. {
  355. DisableNavigation = 0,
  356. EnableNavigation = 1
  357. }
  358. public enum BabylonUpdateOptions
  359. {
  360. StableProduction = 0,
  361. PreviewRelease = 1,
  362. }
  363. public enum BabylonLightingFilter
  364. {
  365. NoFilter = 0,
  366. PoissonSampling = 1,
  367. VarianceShadowMap = 2,
  368. BlurVarianceShadowMap = 3,
  369. SoftPoissonSampling = 4
  370. }
  371. public class BabylonTerrainData
  372. {
  373. public Vector3[] vertices;
  374. public Vector3[] normals;
  375. public Vector2[] uvs;
  376. public int[] triangles;
  377. }
  378. public enum BabylonTerrainFormat
  379. {
  380. Triangles = 0
  381. }
  382. public enum BabylonTerrainResolution
  383. {
  384. FullResolution = 0,
  385. HighResolution = 1,
  386. MediumResolution = 2,
  387. LowResolution = 3,
  388. VeryLowResolution = 4
  389. }
  390. public enum BabylonColliderDetail
  391. {
  392. FullResolution = 0,
  393. HighResolution = 1,
  394. MediumResolution = 2,
  395. LowResolution = 3,
  396. VeryLowResolution = 4,
  397. MinimumResolution = 5
  398. }
  399. public enum BabylonPreviewWindow
  400. {
  401. OpenDefaultBrowser = 0,
  402. AttachUnityBrowser = 1
  403. }
  404. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  405. public sealed class BabylonClassAttribute : Attribute { }
  406. [AttributeUsage(AttributeTargets.Field, Inherited = false)]
  407. public sealed class BabylonPropertyAttribute : PropertyAttribute { }
  408. public abstract class BabylonScriptComponent : MonoBehaviour
  409. {
  410. [Unity3D2Babylon.ReadOnly]
  411. public string babylonClass;
  412. public BabylonTickOptions updateOption;
  413. protected BabylonScriptComponent()
  414. {
  415. this.babylonClass = "BABYLON.ScriptComponent";
  416. this.updateOption = BabylonTickOptions.EnableTick;
  417. }
  418. public virtual void OnExportProperties(ref Unity3D2Babylon.ExportationOptions exportOptions, ref GameObject unityGameObject, ref Dictionary<string, object> propertyBag, string outputPath) { }
  419. }
  420. public abstract class BabylonSceneController : BabylonScriptComponent
  421. {
  422. public BabylonSceneOptions sceneOptions;
  423. public BabylonSkyboxOptions skyboxOptions;
  424. public BabylonLightOptions lightingOptions;
  425. public BabylonManifestOptions manifestOptions;
  426. protected BabylonSceneController()
  427. {
  428. this.babylonClass = "BABYLON.SceneController";
  429. this.updateOption = BabylonTickOptions.EnableTick;
  430. }
  431. public virtual void OnExportGameObject(ref Unity3D2Babylon.ExportationOptions exportOptions, ref GameObject unityGameObject, ref UnityMetaData metaData, ref BabylonScene sceneBuilder, string outputPath) { }
  432. }
  433. }