tab_meshes.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. let _tab_meshes_draw_i: i32;
  2. function tab_meshes_draw(htab: zui_handle_t) {
  3. let ui: zui_t = ui_base_ui;
  4. let statush: i32 = config_raw.layout[layout_size_t.STATUS_H];
  5. if (zui_tab(htab, tr("Meshes")) && statush > ui_status_default_status_h * zui_SCALE(ui)) {
  6. zui_begin_sticky();
  7. ///if (is_paint || is_sculpt)
  8. if (config_raw.touch_ui) {
  9. let row: f32[] = [1 / 6, 1 / 6, 1 / 6, 1 / 6, 1 / 6, 1 / 6];
  10. zui_row(row);
  11. }
  12. else {
  13. let row: f32[] = [1 / 14, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 14];
  14. zui_row(row);
  15. }
  16. ///end
  17. ///if is_lab
  18. if (config_raw.touch_ui) {
  19. let row: f32[] = [1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7];
  20. zui_row(row);
  21. }
  22. else {
  23. let row: f32[] = [1 / 14, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 14];
  24. zui_row(row);
  25. }
  26. ///end
  27. if (zui_button(tr("Import"))) {
  28. ui_menu_draw(function (ui: zui_t) {
  29. if (ui_menu_button(ui, tr("Replace Existing"), map_get(config_keymap, "file_import_assets"))) {
  30. project_import_mesh(true);
  31. }
  32. if (ui_menu_button(ui, tr("Append"))) {
  33. project_import_mesh(false);
  34. }
  35. }, 2);
  36. }
  37. if (ui.is_hovered) zui_tooltip(tr("Import mesh file"));
  38. ///if is_lab
  39. if (zui_button(tr("Set Default"))) {
  40. ui_menu_draw(function (ui: zui_t) {
  41. if (ui_menu_button(ui, tr("Cube"))) {
  42. tab_meshes_set_default_mesh(".Cube");
  43. }
  44. if (ui_menu_button(ui, tr("Plane"))) {
  45. tab_meshes_set_default_mesh(".Plane");
  46. }
  47. if (ui_menu_button(ui, tr("Sphere"))) {
  48. tab_meshes_set_default_mesh(".Sphere");
  49. }
  50. if (ui_menu_button(ui, tr("Cylinder"))) {
  51. tab_meshes_set_default_mesh(".Cylinder");
  52. }
  53. }, 4);
  54. }
  55. ///end
  56. if (zui_button(tr("Flip Normals"))) {
  57. util_mesh_flip_normals();
  58. context_raw.ddirty = 2;
  59. }
  60. if (zui_button(tr("Calculate Normals"))) {
  61. ui_menu_draw(function (ui: zui_t) {
  62. if (ui_menu_button(ui, tr("Smooth"))) {
  63. util_mesh_calc_normals(true);
  64. context_raw.ddirty = 2;
  65. }
  66. if (ui_menu_button(ui, tr("Flat"))) {
  67. util_mesh_calc_normals(false);
  68. context_raw.ddirty = 2;
  69. }
  70. }, 2);
  71. }
  72. if (zui_button(tr("Geometry to Origin"))) {
  73. util_mesh_to_origin();
  74. context_raw.ddirty = 2;
  75. }
  76. if (zui_button(tr("Apply Displacement"))) {
  77. ///if is_paint
  78. util_mesh_apply_displacement(project_layers[0].texpaint_pack);
  79. ///end
  80. ///if is_lab
  81. let displace_strength: f32 = config_raw.displace_strength > 0 ? config_raw.displace_strength : 1.0;
  82. let uv_scale: f32 = scene_meshes[0].data.scale_tex * context_raw.brush_scale;
  83. util_mesh_apply_displacement(brush_output_node_inst.texpaint_pack, 0.05 * displace_strength, uv_scale);
  84. ///end
  85. util_mesh_calc_normals();
  86. context_raw.ddirty = 2;
  87. }
  88. if (zui_button(tr("Rotate"))) {
  89. ui_menu_draw(function (ui: zui_t) {
  90. if (ui_menu_button(ui, tr("Rotate X"))) {
  91. util_mesh_swap_axis(1, 2);
  92. context_raw.ddirty = 2;
  93. }
  94. if (ui_menu_button(ui, tr("Rotate Y"))) {
  95. util_mesh_swap_axis(2, 0);
  96. context_raw.ddirty = 2;
  97. }
  98. if (ui_menu_button(ui, tr("Rotate Z"))) {
  99. util_mesh_swap_axis(0, 1);
  100. context_raw.ddirty = 2;
  101. }
  102. }, 3);
  103. }
  104. zui_end_sticky();
  105. for (let i: i32 = 0; i < project_paint_objects.length; ++i) {
  106. let o: mesh_object_t = project_paint_objects[i];
  107. let h: zui_handle_t = zui_handle(__ID__);
  108. h.selected = o.base.visible;
  109. o.base.visible = zui_check(h, o.base.name);
  110. if (ui.is_hovered && ui.input_released_r) {
  111. _tab_meshes_draw_i = i;
  112. ui_menu_draw(function (ui: zui_t) {
  113. let i: i32 = _tab_meshes_draw_i;
  114. let o: mesh_object_t = project_paint_objects[i];
  115. if (ui_menu_button(ui, tr("Export"))) {
  116. context_raw.export_mesh_index = i + 1;
  117. box_export_show_mesh();
  118. }
  119. if (project_paint_objects.length > 1 && ui_menu_button(ui, tr("Delete"))) {
  120. array_remove(project_paint_objects, o);
  121. while (o.base.children.length > 0) {
  122. let child: object_t = o.base.children[0];
  123. object_set_parent(child, null);
  124. if (project_paint_objects[0].base != child) {
  125. object_set_parent(child, project_paint_objects[0].base);
  126. }
  127. if (o.base.children.length == 0) {
  128. vec4_set_from(project_paint_objects[0].base.transform.scale, o.base.transform.scale);
  129. transform_build_matrix(project_paint_objects[0].base.transform);
  130. }
  131. }
  132. data_delete_mesh(o.data._.handle);
  133. mesh_object_remove(o);
  134. context_raw.paint_object = context_main_object();
  135. util_mesh_merge();
  136. context_raw.ddirty = 2;
  137. }
  138. }, project_paint_objects.length > 1 ? 2 : 1);
  139. }
  140. if (h.changed) {
  141. let visibles: mesh_object_t[] = [];
  142. for (let i: i32 = 0; i < project_paint_objects.length; ++i) {
  143. let p: mesh_object_t = project_paint_objects[i];
  144. if (p.base.visible) {
  145. array_push(visibles, p);
  146. }
  147. }
  148. util_mesh_merge(visibles);
  149. context_raw.ddirty = 2;
  150. }
  151. }
  152. }
  153. }
  154. ///if is_lab
  155. function tab_meshes_set_default_mesh(name: string) {
  156. let mo: mesh_object_t = null;
  157. if (name == ".Plane" || name == ".Sphere") {
  158. let res: i32 = config_raw.rp_supersample > 1.0 ? 2048 : 1024;
  159. let mesh: any = name == ".Plane" ? geom_make_plane(1, 1, res, res) : geom_make_uv_sphere(1.0, res, math_floor(res / 2), false, 2.0);
  160. let raw: any = {
  161. name: "Tessellated",
  162. vertex_arrays: [
  163. { values: mesh.posa, attrib: "pos", data: "short4norm" },
  164. { values: mesh.nora, attrib: "nor", data: "short2norm" },
  165. { values: mesh.texa, attrib: "tex", data: "short2norm" }
  166. ],
  167. index_arrays: [
  168. { values: mesh.inda, material: 0 }
  169. ],
  170. scale_pos: mesh.scale_pos,
  171. scale_tex: mesh.scale_tex
  172. };
  173. let md: mesh_data_t = mesh_data_create(raw);
  174. mo = mesh_object_create(md, context_raw.paint_object.materials);
  175. array_remove(scene_meshes, mo);
  176. mo.base.name = "Tessellated";
  177. }
  178. else {
  179. mo = scene_get_child(name).ext;
  180. }
  181. mo.base.visible = true;
  182. context_raw.ddirty = 2;
  183. context_raw.paint_object = mo;
  184. project_paint_objects[0] = mo;
  185. if (ui_header_worktab.position == space_type_t.SPACE3D) {
  186. scene_meshes = [mo];
  187. }
  188. ///if (krom_direct3d12 || krom_vulkan || krom_metal)
  189. render_path_raytrace_ready = false;
  190. ///end
  191. }
  192. ///end