args.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. let args_use: bool = false;
  2. let args_asset_path: string = "";
  3. let args_background: bool = false;
  4. ///if (is_paint || is_lab)
  5. let args_export_textures: bool = false;
  6. let args_export_textures_type: string = "";
  7. let args_export_textures_preset: string = "";
  8. let args_export_textures_path: string = "";
  9. ///end
  10. ///if (is_paint || is_sculpt)
  11. let args_reimport_mesh: bool = false;
  12. let args_export_mesh: bool = false;
  13. let args_export_mesh_path: string = "";
  14. ///end
  15. ///if is_paint
  16. let args_export_material: bool = false;
  17. let args_export_material_path: string = "";
  18. ///end
  19. function args_parse() {
  20. if (krom_get_arg_count() > 1) {
  21. args_use = true;
  22. let i: i32 = 0;
  23. while (i < krom_get_arg_count()) {
  24. // Process each arg
  25. let current_arg: string = krom_get_arg(i);
  26. if (path_is_project(current_arg)) {
  27. project_filepath = current_arg;
  28. }
  29. else if (current_arg == "--b" || current_arg == "--background") {
  30. args_background = true;
  31. }
  32. ///if (is_paint || is_lab)
  33. else if (path_is_texture(current_arg)) {
  34. args_asset_path = current_arg;
  35. }
  36. else if (current_arg == "--export-textures" && (i + 3) <= krom_get_arg_count()) {
  37. args_export_textures = true;
  38. ++i;
  39. args_export_textures_type = krom_get_arg(i);
  40. ++i;
  41. args_export_textures_preset = krom_get_arg(i);
  42. ++i;
  43. args_export_textures_path = krom_get_arg(i);
  44. }
  45. ///end
  46. ///if (is_paint || is_sculpt)
  47. else if (current_arg == "--reload-mesh") {
  48. args_reimport_mesh = true;
  49. }
  50. else if (current_arg == "--export-mesh" && (i + 1) <= krom_get_arg_count()) {
  51. args_export_mesh = true;
  52. ++i;
  53. args_export_mesh_path = krom_get_arg(i);
  54. }
  55. else if (path_is_mesh(current_arg) || (i > 1 && !starts_with(current_arg, "-") && path_is_folder(current_arg))) {
  56. args_asset_path = current_arg;
  57. }
  58. ///end
  59. ///if is_paint
  60. else if (current_arg == "--export-material" && (i + 1) <= krom_get_arg_count()) {
  61. args_export_material = true;
  62. ++i;
  63. args_export_material_path = krom_get_arg(i);
  64. }
  65. ///end
  66. ++i;
  67. }
  68. }
  69. }
  70. function args_run() {
  71. if (args_use) {
  72. app_notify_on_init(function () {
  73. if (project_filepath != "") {
  74. import_arm_run_project(project_filepath);
  75. }
  76. else if (args_asset_path != "") {
  77. import_asset_run(args_asset_path, -1, -1, false);
  78. ///if is_paint
  79. if (path_is_texture(args_asset_path)) {
  80. ui_base_show_2d_view(view_2d_type_t.ASSET);
  81. }
  82. ///end
  83. }
  84. ///if (is_paint || is_sculpt)
  85. else if (args_reimport_mesh) {
  86. project_reimport_mesh();
  87. }
  88. ///end
  89. ///if (is_paint || is_lab)
  90. if (args_export_textures) {
  91. if (args_export_textures_type == "png" ||
  92. args_export_textures_type == "jpg" ||
  93. args_export_textures_type == "exr16" ||
  94. args_export_textures_type == "exr32") {
  95. if (path_is_folder(args_export_textures_path)) {
  96. // Applying the correct format type from args
  97. if (args_export_textures_type == "png") {
  98. ///if is_paint
  99. base_bits_handle.position = texture_bits_t.BITS8;
  100. ///end
  101. context_raw.format_type = texture_ldr_format_t.PNG;
  102. }
  103. else if (args_export_textures_type == "jpg") {
  104. ///if is_paint
  105. base_bits_handle.position = texture_bits_t.BITS8;
  106. ///end
  107. context_raw.format_type = texture_ldr_format_t.JPG;
  108. }
  109. else if (args_export_textures_type == "exr16") {
  110. ///if is_paint
  111. base_bits_handle.position = texture_bits_t.BITS16;
  112. ///end
  113. }
  114. else if (args_export_textures_type == "exr32") {
  115. ///if is_paint
  116. base_bits_handle.position = texture_bits_t.BITS32;
  117. ///end
  118. }
  119. ///if is_paint
  120. context_raw.layers_export = export_mode_t.VISIBLE;
  121. ///end
  122. // Get export preset and apply the correct one from args
  123. box_export_files = file_read_directory(path_data() + path_sep + "export_presets");
  124. for (let i: i32 = 0; i < box_export_files.length; ++i) {
  125. box_export_files[i] = substring(box_export_files[i], 0, box_export_files[i].length - 5); // Strip .json
  126. }
  127. let file: string = "export_presets/" + box_export_files[0] + ".json";
  128. for (let i: i32 = 0; i < box_export_files.length; ++i) {
  129. let f: string = box_export_files[i];
  130. if (f == args_export_textures_preset) {
  131. file = "export_presets/" + box_export_files[array_index_of(box_export_files, f)] + ".json";
  132. }
  133. }
  134. let blob: buffer_t = data_get_blob(file);
  135. box_export_preset = json_parse(sys_buffer_to_string(blob));
  136. data_delete_blob("export_presets/" + file);
  137. // Export queue
  138. app_notify_on_init(function () {
  139. export_texture_run(args_export_textures_path);
  140. });
  141. }
  142. else {
  143. krom_log(tr("Invalid export directory"));
  144. }
  145. }
  146. else {
  147. krom_log(tr("Invalid texture type"));
  148. }
  149. }
  150. ///end
  151. ///if (is_paint || is_sculpt)
  152. else if (args_export_mesh) {
  153. if (path_is_folder(args_export_mesh_path)) {
  154. let f: string = ui_files_filename;
  155. if (f == "") {
  156. f = tr("untitled");
  157. }
  158. export_mesh_run(args_export_mesh_path + path_sep + f, null, false);
  159. }
  160. else {
  161. krom_log(tr("Invalid export directory"));
  162. }
  163. }
  164. ///end
  165. ///if is_paint
  166. else if (args_export_material) {
  167. context_raw.write_icon_on_export = true;
  168. export_arm_run_material(args_export_material_path);
  169. }
  170. ///end
  171. if (args_background) {
  172. sys_stop();
  173. }
  174. });
  175. }
  176. }