types.vala 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /*
  2. * Copyright (c) 2012-2025 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. namespace Crown
  6. {
  7. const string OBJECT_TYPE_ACTOR = "actor";
  8. const string OBJECT_TYPE_ANIMATION_FRAME = "animation_frame";
  9. const string OBJECT_TYPE_ANIMATION_STATE_MACHINE = "animation_state_machine";
  10. const string OBJECT_TYPE_CAMERA = "camera";
  11. const string OBJECT_TYPE_COLLIDER = "collider";
  12. const string OBJECT_TYPE_FILE = "file";
  13. const string OBJECT_TYPE_FOG = "fog";
  14. const string OBJECT_TYPE_FONT = "font";
  15. const string OBJECT_TYPE_LEVEL = "level";
  16. const string OBJECT_TYPE_LIGHT = "light";
  17. const string OBJECT_TYPE_MATERIAL = "material";
  18. const string OBJECT_TYPE_MESH = "mesh";
  19. const string OBJECT_TYPE_MESH_ANIMATION = "mesh_animation";
  20. const string OBJECT_TYPE_MESH_BONE = "mesh_bone";
  21. const string OBJECT_TYPE_MESH_RENDERER = "mesh_renderer";
  22. const string OBJECT_TYPE_MESH_SKELETON = "mesh_skeleton";
  23. const string OBJECT_TYPE_NODE_ANIMATION = "node_animation";
  24. const string OBJECT_TYPE_NODE_TRANSITION = "node_transition";
  25. const string OBJECT_TYPE_SCRIPT = "script";
  26. const string OBJECT_TYPE_SOUND = "sound";
  27. const string OBJECT_TYPE_SOUND_SOURCE = "sound_source";
  28. const string OBJECT_TYPE_SPRITE = "sprite";
  29. const string OBJECT_TYPE_SPRITE_ANIMATION = "sprite_animation";
  30. const string OBJECT_TYPE_SPRITE_RENDERER = "sprite_renderer";
  31. const string OBJECT_TYPE_STATE_MACHINE = "state_machine";
  32. const string OBJECT_TYPE_STATE_MACHINE_NODE = "state_machine_node";
  33. const string OBJECT_TYPE_STATE_MACHINE_VARIABLE = "state_machine_variable";
  34. const string OBJECT_TYPE_TEXTURE = "texture";
  35. const string OBJECT_TYPE_TRANSFORM = "transform";
  36. const string OBJECT_TYPE_UNIT = "unit";
  37. public static void node_name_enum_callback(InputField enum_property, InputEnum combo, Project project)
  38. {
  39. try {
  40. string path = ResourceId.path(OBJECT_TYPE_MESH, (string)enum_property.union_value());
  41. Mesh mesh = Mesh.load_from_path(project, path);
  42. combo.clear();
  43. foreach (var node in mesh._nodes)
  44. combo.append(node, node);
  45. combo.value = combo.any_valid_id();
  46. } catch (JsonSyntaxError e) {
  47. loge(e.message);
  48. }
  49. }
  50. public static void scene_resource_callback(InputField enum_property, InputResource chooser, Project project)
  51. {
  52. if (enum_property.union_value() == "mesh")
  53. chooser.set_union_value("core/units/primitives/cube");
  54. }
  55. public static void shape_resource_callback(InputField enum_property, InputEnum combo, Project project)
  56. {
  57. if (enum_property.union_value() == "inline")
  58. combo.set_union_value("box");
  59. }
  60. public static void class_enum_callback(InputField property_enum, InputEnum combo, Project project)
  61. {
  62. try {
  63. string path = ResourceId.path("physics_config", "global");
  64. Hashtable global = SJSON.load_from_path(project.absolute_path(path));
  65. string prev_enum = combo.value;
  66. combo.clear();
  67. if (global.has_key("actors")) {
  68. Hashtable obj = (Hashtable)global["actors"];
  69. foreach (var e in obj)
  70. combo.append(e.key, e.key);
  71. }
  72. combo.value = prev_enum;
  73. } catch (JsonSyntaxError e) {
  74. loge(e.message);
  75. }
  76. }
  77. public static void collision_filter_enum_callback(InputField property_enum, InputEnum combo, Project project)
  78. {
  79. try {
  80. string path = ResourceId.path("physics_config", "global");
  81. Hashtable global = SJSON.load_from_path(project.absolute_path(path));
  82. string prev_enum = combo.value;
  83. combo.clear();
  84. if (global.has_key("collision_filters")) {
  85. Hashtable obj = (Hashtable)global["collision_filters"];
  86. foreach (var e in obj)
  87. combo.append(e.key, e.key);
  88. }
  89. combo.value = prev_enum;
  90. } catch (JsonSyntaxError e) {
  91. loge(e.message);
  92. }
  93. }
  94. public static void material_enum_callback(InputField property_enum, InputEnum combo, Project project)
  95. {
  96. try {
  97. string path = ResourceId.path("physics_config", "global");
  98. Hashtable global = SJSON.load_from_path(project.absolute_path(path));
  99. string prev_enum = combo.value;
  100. combo.clear();
  101. if (global.has_key("materials")) {
  102. Hashtable obj = (Hashtable)global["materials"];
  103. foreach (var e in obj)
  104. combo.append(e.key, e.key);
  105. }
  106. combo.value = prev_enum;
  107. } catch (JsonSyntaxError e) {
  108. loge(e.message);
  109. }
  110. }
  111. public static void create_object_types(Database database)
  112. {
  113. PropertyDefinition[] properties;
  114. properties =
  115. {
  116. PropertyDefinition()
  117. {
  118. type = PropertyType.VECTOR3,
  119. name = "data.position",
  120. },
  121. PropertyDefinition()
  122. {
  123. type = PropertyType.QUATERNION,
  124. name = "data.rotation",
  125. },
  126. PropertyDefinition()
  127. {
  128. type = PropertyType.VECTOR3,
  129. name = "data.scale",
  130. min = VECTOR3_ZERO,
  131. deffault = VECTOR3_ONE,
  132. },
  133. };
  134. database.create_object_type(OBJECT_TYPE_TRANSFORM, properties);
  135. properties =
  136. {
  137. PropertyDefinition()
  138. {
  139. type = PropertyType.STRING,
  140. name = "data.mesh_resource",
  141. label = "Scene",
  142. editor = PropertyEditorType.RESOURCE,
  143. resource_type = OBJECT_TYPE_MESH,
  144. },
  145. PropertyDefinition()
  146. {
  147. type = PropertyType.STRING,
  148. name = "data.geometry_name",
  149. label = "Node",
  150. editor = PropertyEditorType.ENUM,
  151. enum_property = "data.mesh_resource",
  152. enum_callback = node_name_enum_callback,
  153. },
  154. PropertyDefinition()
  155. {
  156. type = PropertyType.STRING,
  157. name = "data.material",
  158. editor = PropertyEditorType.RESOURCE,
  159. resource_type = OBJECT_TYPE_MATERIAL,
  160. },
  161. PropertyDefinition()
  162. {
  163. type = PropertyType.BOOL,
  164. name = "data.visible",
  165. },
  166. PropertyDefinition()
  167. {
  168. type = PropertyType.BOOL,
  169. name = "data.cast_shadows",
  170. },
  171. };
  172. database.create_object_type(OBJECT_TYPE_MESH_RENDERER, properties);
  173. properties =
  174. {
  175. PropertyDefinition()
  176. {
  177. type = PropertyType.STRING,
  178. name = "data.sprite_resource",
  179. label = "Sprite",
  180. editor = PropertyEditorType.RESOURCE,
  181. resource_type = OBJECT_TYPE_SPRITE,
  182. },
  183. PropertyDefinition()
  184. {
  185. type = PropertyType.STRING,
  186. name = "data.material",
  187. editor = PropertyEditorType.RESOURCE,
  188. resource_type = OBJECT_TYPE_MATERIAL,
  189. },
  190. PropertyDefinition()
  191. {
  192. type = PropertyType.DOUBLE,
  193. name = "data.layer",
  194. min = 0.0,
  195. max = 7.0,
  196. },
  197. PropertyDefinition()
  198. {
  199. type = PropertyType.DOUBLE,
  200. name = "data.depth",
  201. min = 0.0,
  202. max = (double)uint32.MAX,
  203. },
  204. PropertyDefinition()
  205. {
  206. type = PropertyType.BOOL,
  207. name = "data.visible",
  208. },
  209. PropertyDefinition()
  210. {
  211. type = PropertyType.BOOL,
  212. name = "data.flip_x",
  213. },
  214. PropertyDefinition()
  215. {
  216. type = PropertyType.BOOL,
  217. name = "data.flip_y",
  218. },
  219. };
  220. database.create_object_type(OBJECT_TYPE_SPRITE_RENDERER, properties);
  221. properties =
  222. {
  223. PropertyDefinition()
  224. {
  225. type = PropertyType.STRING,
  226. name = "data.type",
  227. editor = PropertyEditorType.ENUM,
  228. enum_values = { "directional", "omni", "spot" },
  229. },
  230. PropertyDefinition()
  231. {
  232. type = PropertyType.DOUBLE,
  233. name = "data.range",
  234. min = 0.0,
  235. },
  236. PropertyDefinition()
  237. {
  238. type = PropertyType.DOUBLE,
  239. name = "data.intensity",
  240. min = 0.0,
  241. },
  242. PropertyDefinition()
  243. {
  244. type = PropertyType.DOUBLE,
  245. name = "data.spot_angle",
  246. editor = PropertyEditorType.ANGLE,
  247. min = 0.0,
  248. max = 90.0,
  249. },
  250. PropertyDefinition()
  251. {
  252. type = PropertyType.VECTOR3,
  253. name = "data.color",
  254. editor = PropertyEditorType.COLOR,
  255. min = VECTOR3_ZERO,
  256. max = VECTOR3_ONE,
  257. },
  258. PropertyDefinition()
  259. {
  260. type = PropertyType.DOUBLE,
  261. name = "data.shadow_bias",
  262. min = 0.0,
  263. max = 1.0,
  264. deffault = 0.0001,
  265. },
  266. PropertyDefinition()
  267. {
  268. type = PropertyType.BOOL,
  269. name = "data.cast_shadows",
  270. deffault = true,
  271. },
  272. };
  273. database.create_object_type(OBJECT_TYPE_LIGHT, properties);
  274. properties =
  275. {
  276. PropertyDefinition()
  277. {
  278. type = PropertyType.STRING,
  279. name = "data.projection",
  280. editor = PropertyEditorType.ENUM,
  281. enum_values = { "orthographic", "perspective" },
  282. },
  283. PropertyDefinition()
  284. {
  285. type = PropertyType.DOUBLE,
  286. name = "data.fov",
  287. label = "FOV",
  288. editor = PropertyEditorType.ANGLE,
  289. min = 0.0,
  290. max = 90.0
  291. },
  292. PropertyDefinition()
  293. {
  294. type = PropertyType.DOUBLE,
  295. name = "data.near_range",
  296. deffault = 0.1,
  297. },
  298. PropertyDefinition()
  299. {
  300. type = PropertyType.DOUBLE,
  301. name = "data.far_range",
  302. deffault = 1000.0,
  303. },
  304. };
  305. database.create_object_type(OBJECT_TYPE_CAMERA, properties);
  306. properties =
  307. {
  308. PropertyDefinition()
  309. {
  310. type = PropertyType.STRING,
  311. name = "data.source",
  312. editor = PropertyEditorType.ENUM,
  313. enum_values = { "mesh", "inline" },
  314. },
  315. PropertyDefinition()
  316. {
  317. type = PropertyType.STRING,
  318. name = "data.scene",
  319. editor = PropertyEditorType.RESOURCE,
  320. resource_type = OBJECT_TYPE_MESH,
  321. enum_property = "data.source",
  322. resource_callback = scene_resource_callback
  323. },
  324. PropertyDefinition()
  325. {
  326. type = PropertyType.STRING,
  327. name = "data.name",
  328. label = "Node",
  329. editor = PropertyEditorType.ENUM,
  330. enum_property = "data.scene",
  331. enum_callback = node_name_enum_callback,
  332. },
  333. PropertyDefinition()
  334. {
  335. type = PropertyType.STRING,
  336. name = "data.shape",
  337. editor = PropertyEditorType.ENUM,
  338. enum_values = { "sphere", "capsule", "box", "convex_hull", "mesh" },
  339. enum_property = "data.source",
  340. enum_callback = shape_resource_callback,
  341. },
  342. PropertyDefinition()
  343. {
  344. type = PropertyType.VECTOR3,
  345. name = "data.collider_data.position",
  346. },
  347. PropertyDefinition()
  348. {
  349. type = PropertyType.QUATERNION,
  350. name = "data.collider_data.rotation",
  351. },
  352. PropertyDefinition()
  353. {
  354. type = PropertyType.VECTOR3,
  355. name = "data.collider_data.half_extents", // Box only.
  356. min = VECTOR3_ZERO,
  357. deffault = Vector3(0.5, 0.5, 0.5),
  358. },
  359. PropertyDefinition()
  360. {
  361. type = PropertyType.DOUBLE,
  362. name = "data.collider_data.radius", // Sphere and capsule only.
  363. min = 0.0,
  364. deffault = 0.5,
  365. },
  366. PropertyDefinition()
  367. {
  368. type = PropertyType.DOUBLE,
  369. name = "data.collider_data.height", // Capsule only.
  370. min = 0.0,
  371. deffault = 1.0,
  372. },
  373. };
  374. database.create_object_type(OBJECT_TYPE_COLLIDER, properties);
  375. properties =
  376. {
  377. PropertyDefinition()
  378. {
  379. type = PropertyType.STRING,
  380. name = "_global_physics_config",
  381. deffault = "global",
  382. editor = PropertyEditorType.RESOURCE,
  383. resource_type = "physics_config",
  384. hidden = true,
  385. },
  386. PropertyDefinition()
  387. {
  388. type = PropertyType.STRING,
  389. name = "data.class",
  390. editor = PropertyEditorType.ENUM,
  391. enum_property = "_global_physics_config",
  392. enum_callback = class_enum_callback
  393. },
  394. PropertyDefinition()
  395. {
  396. type = PropertyType.STRING,
  397. name = "data.collision_filter",
  398. editor = PropertyEditorType.ENUM,
  399. enum_property = "_global_physics_config",
  400. enum_callback = collision_filter_enum_callback
  401. },
  402. PropertyDefinition()
  403. {
  404. type = PropertyType.STRING,
  405. name = "data.material",
  406. editor = PropertyEditorType.ENUM,
  407. enum_property = "_global_physics_config",
  408. enum_callback = material_enum_callback
  409. },
  410. PropertyDefinition()
  411. {
  412. type = PropertyType.DOUBLE,
  413. name = "data.mass",
  414. min = 0.0,
  415. deffault = 1.0,
  416. },
  417. PropertyDefinition()
  418. {
  419. type = PropertyType.BOOL,
  420. name = "data.lock_translation_x",
  421. },
  422. PropertyDefinition()
  423. {
  424. type = PropertyType.BOOL,
  425. name = "data.lock_translation_y",
  426. },
  427. PropertyDefinition()
  428. {
  429. type = PropertyType.BOOL,
  430. name = "data.lock_translation_z",
  431. },
  432. PropertyDefinition()
  433. {
  434. type = PropertyType.BOOL,
  435. name = "data.lock_rotation_x",
  436. },
  437. PropertyDefinition()
  438. {
  439. type = PropertyType.BOOL,
  440. name = "data.lock_rotation_y",
  441. },
  442. PropertyDefinition()
  443. {
  444. type = PropertyType.BOOL,
  445. name = "data.lock_rotation_z",
  446. },
  447. };
  448. database.create_object_type(OBJECT_TYPE_ACTOR, properties);
  449. properties =
  450. {
  451. PropertyDefinition()
  452. {
  453. type = PropertyType.STRING,
  454. name = "data.script_resource",
  455. label = "Script",
  456. editor = PropertyEditorType.RESOURCE,
  457. resource_type = "lua"
  458. },
  459. };
  460. database.create_object_type(OBJECT_TYPE_SCRIPT, properties);
  461. properties =
  462. {
  463. PropertyDefinition()
  464. {
  465. type = PropertyType.STRING,
  466. name = "data.state_machine_resource",
  467. label = "State Machine",
  468. editor = PropertyEditorType.RESOURCE,
  469. resource_type = OBJECT_TYPE_STATE_MACHINE
  470. },
  471. };
  472. database.create_object_type(OBJECT_TYPE_ANIMATION_STATE_MACHINE, properties);
  473. properties =
  474. {
  475. PropertyDefinition()
  476. {
  477. type = PropertyType.VECTOR3,
  478. name = "position",
  479. },
  480. PropertyDefinition()
  481. {
  482. type = PropertyType.QUATERNION,
  483. name = "rotation",
  484. },
  485. PropertyDefinition()
  486. {
  487. type = PropertyType.STRING,
  488. name = "name",
  489. editor = PropertyEditorType.RESOURCE,
  490. resource_type = OBJECT_TYPE_SOUND,
  491. },
  492. PropertyDefinition()
  493. {
  494. type = PropertyType.DOUBLE,
  495. name = "range",
  496. min = 0.0,
  497. deffault = 10.0,
  498. },
  499. PropertyDefinition()
  500. {
  501. type = PropertyType.DOUBLE,
  502. name = "volume",
  503. min = 0.0,
  504. max = 1.0,
  505. deffault = 1.0,
  506. },
  507. PropertyDefinition()
  508. {
  509. type = PropertyType.BOOL,
  510. name = "loop",
  511. },
  512. PropertyDefinition()
  513. {
  514. type = PropertyType.STRING,
  515. name = "group",
  516. deffault = "music",
  517. },
  518. };
  519. database.create_object_type(OBJECT_TYPE_SOUND_SOURCE, properties);
  520. properties =
  521. {
  522. PropertyDefinition()
  523. {
  524. type = PropertyType.VECTOR3,
  525. name = "data.color",
  526. editor = PropertyEditorType.COLOR,
  527. min = VECTOR3_ZERO,
  528. max = VECTOR3_ONE,
  529. deffault = VECTOR3_ONE,
  530. },
  531. PropertyDefinition()
  532. {
  533. type = PropertyType.DOUBLE,
  534. name = "data.density",
  535. min = 0.0,
  536. deffault = 0.02
  537. },
  538. PropertyDefinition()
  539. {
  540. type = PropertyType.DOUBLE,
  541. name = "data.range_min",
  542. min = 0.0,
  543. },
  544. PropertyDefinition()
  545. {
  546. type = PropertyType.DOUBLE,
  547. name = "data.range_max",
  548. min = 0.0,
  549. deffault = 1000.0
  550. },
  551. PropertyDefinition()
  552. {
  553. type = PropertyType.DOUBLE,
  554. name = "data.sun_blend",
  555. min = 0.0,
  556. max = 1.0,
  557. deffault = 0.0
  558. },
  559. PropertyDefinition()
  560. {
  561. type = PropertyType.BOOL,
  562. name = "data.enabled",
  563. deffault = true,
  564. },
  565. };
  566. database.create_object_type(OBJECT_TYPE_FOG, properties);
  567. }
  568. } /* namespace Crown */