tab_object.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. function tab_object_draw(htab: ui_handle_t) {
  2. let ui: ui_t = ui_base_ui;
  3. if (ui_tab(htab, tr("Object"))) {
  4. if (context_raw.selected_object != null) {
  5. let h: ui_handle_t = ui_handle(__ID__);
  6. h.selected = context_raw.selected_object.visible;
  7. context_raw.selected_object.visible = ui_check(h, "Visible");
  8. if (h.changed) {
  9. // Rebuild full vb for path-tracing
  10. util_mesh_merge();
  11. }
  12. let t: transform_t = context_raw.selected_object.transform;
  13. let rot: vec4_t = quat_get_euler(t.rot);
  14. rot = vec4_mult(rot, 180 / 3.141592);
  15. let f: f32 = 0.0;
  16. let changed: bool = false;
  17. ui_text("Transform", ui_align_t.LEFT, ui.ops.theme.SEPARATOR_COL);
  18. ui_row4();
  19. ui_text("Loc");
  20. h = ui_handle(__ID__);
  21. h.text = f32_to_string(t.loc.x);
  22. f = parse_float(ui_text_input(h, "X"));
  23. if (h.changed) {
  24. changed = true;
  25. t.loc.x = f;
  26. }
  27. h = ui_handle(__ID__);
  28. h.text = f32_to_string(t.loc.y);
  29. f = parse_float(ui_text_input(h, "Y"));
  30. if (h.changed) {
  31. changed = true;
  32. t.loc.y = f;
  33. }
  34. h = ui_handle(__ID__);
  35. h.text = f32_to_string(t.loc.z);
  36. f = parse_float(ui_text_input(h, "Z"));
  37. if (h.changed) {
  38. changed = true;
  39. t.loc.z = f;
  40. }
  41. ui_row4();
  42. ui_text("Rotation");
  43. h = ui_handle(__ID__);
  44. h.text = f32_to_string(rot.x);
  45. f = parse_float(ui_text_input(h, "X"));
  46. if (h.changed) {
  47. changed = true;
  48. rot.x = f;
  49. }
  50. h = ui_handle(__ID__);
  51. h.text = f32_to_string(rot.y);
  52. f = parse_float(ui_text_input(h, "Y"));
  53. if (h.changed) {
  54. changed = true;
  55. rot.y = f;
  56. }
  57. h = ui_handle(__ID__);
  58. h.text = f32_to_string(rot.z);
  59. f = parse_float(ui_text_input(h, "Z"));
  60. if (h.changed) {
  61. changed = true;
  62. rot.z = f;
  63. }
  64. ui_row4();
  65. ui_text("Scale");
  66. h = ui_handle(__ID__);
  67. h.text = f32_to_string(t.scale.x);
  68. f = parse_float(ui_text_input(h, "X"));
  69. if (h.changed) {
  70. changed = true;
  71. t.scale.x = f;
  72. }
  73. h = ui_handle(__ID__);
  74. h.text = f32_to_string(t.scale.y);
  75. f = parse_float(ui_text_input(h, "Y"));
  76. if (h.changed) {
  77. changed = true;
  78. t.scale.y = f;
  79. }
  80. h = ui_handle(__ID__);
  81. h.text = f32_to_string(t.scale.z);
  82. f = parse_float(ui_text_input(h, "Z"));
  83. if (h.changed) {
  84. changed = true;
  85. t.scale.z = f;
  86. }
  87. ui_row4();
  88. ui_text("Dimensions");
  89. h = ui_handle(__ID__);
  90. h.text = f32_to_string(t.dim.x);
  91. f = parse_float(ui_text_input(h, "X"));
  92. if (h.changed) {
  93. changed = true;
  94. t.dim.x = f;
  95. }
  96. h = ui_handle(__ID__);
  97. h.text = f32_to_string(t.dim.y);
  98. f = parse_float(ui_text_input(h, "Y"));
  99. if (h.changed) {
  100. changed = true;
  101. t.dim.y = f;
  102. }
  103. h = ui_handle(__ID__);
  104. h.text = f32_to_string(t.dim.z);
  105. f = parse_float(ui_text_input(h, "Z"));
  106. if (h.changed) {
  107. changed = true;
  108. t.dim.z = f;
  109. }
  110. if (changed) {
  111. rot = vec4_mult(rot, 3.141592 / 180);
  112. context_raw.selected_object.transform.rot = quat_from_euler(rot.x, rot.y, rot.z);
  113. transform_build_matrix(context_raw.selected_object.transform);
  114. transform_compute_dim(context_raw.selected_object.transform);
  115. ///if arm_physics
  116. let pb: physics_body_t = map_get(physics_body_object_map, context_raw.selected_object.uid);
  117. if (pb != null) {
  118. physics_body_sync_transform(pb);
  119. }
  120. ///end
  121. }
  122. ui_text("Physics", ui_align_t.LEFT, ui.ops.theme.SEPARATOR_COL);
  123. let pb: physics_body_t = map_get(physics_body_object_map, context_raw.selected_object.uid);
  124. let hshape: ui_handle_t = ui_handle(__ID__);
  125. let shape_combo: string[] = [
  126. tr("None"),
  127. tr("Box"),
  128. tr("Sphere"),
  129. tr("Convex Hull"),
  130. tr("Terrain"),
  131. tr("Mesh"),
  132. ];
  133. hshape.position = pb != null ? pb.shape + 1 : 0;
  134. ui_combo(hshape, shape_combo, tr("Shape"), true);
  135. let hdynamic: ui_handle_t = ui_handle(__ID__);
  136. hdynamic.selected = pb != null ? pb.mass > 0 : false;
  137. ui_check(hdynamic, "Dynamic");
  138. if (hshape.changed || hdynamic.changed) {
  139. sim_remove_body(context_raw.selected_object.uid);
  140. if (hshape.position > 0) {
  141. sim_add_body(context_raw.selected_object, hshape.position - 1, hdynamic.selected ? 1.0 : 0.0);
  142. }
  143. }
  144. ui_text("Script", ui_align_t.LEFT, ui.ops.theme.SEPARATOR_COL);
  145. let script: string = map_get(sim_object_script_map, context_raw.selected_object);
  146. if (script == null) {
  147. script = "";
  148. }
  149. let hscript: ui_handle_t = ui_handle(__ID__);
  150. hscript.text = script;
  151. let _font: g2_font_t = ui.ops.font;
  152. let _font_size: i32 = ui.font_size;
  153. let fmono: g2_font_t = data_get_font("font_mono.ttf");
  154. ui_set_font(ui, fmono);
  155. ui.font_size = math_floor(15 * ui_SCALE(ui));
  156. ui_text_area_coloring = tab_script_get_text_coloring();
  157. ui_text_area(hscript);
  158. ui_text_area_coloring = null;
  159. ui_set_font(ui, _font);
  160. ui.font_size = _font_size;
  161. script = hscript.text;
  162. map_set(sim_object_script_map, context_raw.selected_object, script);
  163. }
  164. }
  165. }