2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-20 16:13:54 +01:00
|
|
|
let tab_objects_material_id: i32 = 0;
|
2024-03-24 10:26:56 +01:00
|
|
|
let tab_objects_line_counter: i32 = 0;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-20 16:13:54 +01:00
|
|
|
function tab_objects_roundfp(f: f32, precision: i32 = 2): f32 {
|
2024-03-14 15:31:22 +01:00
|
|
|
f *= math_pow(10, precision);
|
|
|
|
|
return math_round(f) / math_pow(10, precision);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
function tab_objects_import_mesh_done() {
|
|
|
|
|
object_set_parent(project_paint_objects.pop().base, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tab_objects_draw_menu(ui: zui_t) {
|
|
|
|
|
if (ui_menu_button(ui, "Assign Material")) {
|
|
|
|
|
tab_objects_material_id++;
|
|
|
|
|
|
|
|
|
|
for (let i: i32 = 0; i < _scene_raw.shader_datas.length; ++i) {
|
|
|
|
|
let sh: shader_data_t = _scene_raw.shader_datas[i];
|
|
|
|
|
if (sh.name == "Material_data") {
|
|
|
|
|
let s: shader_data_t = json_parse(json_stringify(sh));
|
|
|
|
|
s.name = "TempMaterial_data" + tab_objects_material_id;
|
|
|
|
|
array_push(_scene_raw.shader_datas, s);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
for (let i: i32 = 0; i < _scene_raw.material_datas.length; ++i) {
|
|
|
|
|
let mat: material_data_t = _scene_raw.material_datas[i];
|
|
|
|
|
if (mat.name == "Material") {
|
|
|
|
|
let m: material_data_t = json_parse(json_stringify(mat));
|
|
|
|
|
m.name = "TempMaterial" + tab_objects_material_id;
|
|
|
|
|
m.shader = "TempMaterial_data" + tab_objects_material_id;
|
|
|
|
|
array_push(_scene_raw.material_datas, m);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
let md: material_data_t = data_get_material("Scene", "TempMaterial" + tab_objects_material_id);
|
|
|
|
|
let mo: mesh_object_t = current_object.ext;
|
|
|
|
|
mo.materials = [md];
|
|
|
|
|
make_material_parse_mesh_preview_material(md);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
function tab_objects_draw_list(list_handle: zui_handle_t, current_object: object_t) {
|
|
|
|
|
if (char_at(current_object.name, 0) == ".") {
|
|
|
|
|
return; // Hidden
|
|
|
|
|
}
|
|
|
|
|
let b: bool = false;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
// Highlight every other line
|
|
|
|
|
if (tab_objects_line_counter % 2 == 0) {
|
|
|
|
|
g2_set_color(ui.t.SEPARATOR_COL);
|
|
|
|
|
g2_fill_rect(0, ui._y, ui._window_w, zui_ELEMENT_H(ui));
|
|
|
|
|
g2_set_color(0xffffffff);
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
// Highlight selected line
|
|
|
|
|
if (current_object == context_context_raw.selected_object) {
|
|
|
|
|
g2_set_color(0xff205d9c);
|
|
|
|
|
g2_fill_rect(0, ui._y, ui._window_w, zui_ELEMENT_H(ui));
|
|
|
|
|
g2_set_color(0xffffffff);
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
if (current_object.children.length > 0) {
|
|
|
|
|
zui_row([1 / 13, 12 / 13]);
|
|
|
|
|
b = zui_panel(zui_nest(list_handle, tab_objects_line_counter, {selected: true}), "", true, false, false);
|
|
|
|
|
zui_text(current_object.name);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ui._x += 18; // Sign offset
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
// Draw line that shows parent relations
|
|
|
|
|
g2_set_color(ui.t.ACCENT_COL);
|
|
|
|
|
g2_draw_line(ui._x - 10, ui._y + zui_ELEMENT_H(ui) / 2, ui._x, ui._y + zui_ELEMENT_H(ui) / 2);
|
|
|
|
|
g2_set_color(0xffffffff);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
zui_text(current_object.name);
|
|
|
|
|
ui._x -= 18;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
tab_objects_line_counter++;
|
|
|
|
|
// Undo applied offset for row drawing caused by end_element()
|
|
|
|
|
ui._y -= zui_ELEMENT_OFFSET(ui);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
if (ui.is_released) {
|
|
|
|
|
context_context_raw.selected_object = current_object;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
if (ui.is_hovered && ui.input_released_r) {
|
|
|
|
|
ui_menu_draw(tab_objects_draw_menu, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b) {
|
|
|
|
|
let current_y = ui._y;
|
|
|
|
|
for (let i: i32 = 0; i < current_object.children.length; ++i) {
|
|
|
|
|
let child: object_t = current_object.children[i];
|
|
|
|
|
// ui.indent();
|
|
|
|
|
tab_objects_draw_list(list_handle, child);
|
|
|
|
|
// ui.unindent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw line that shows parent relations
|
|
|
|
|
g2_set_color(ui.t.ACCENT_COL);
|
|
|
|
|
g2_draw_line(ui._x + 14, current_y, ui._x + 14, ui._y - zui_ELEMENT_H(ui) / 2);
|
|
|
|
|
g2_set_color(0xffffffff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tab_objects_draw(htab: zui_handle_t) {
|
|
|
|
|
let ui = ui_base_ui;
|
|
|
|
|
if (zui_tab(htab, tr("Objects"))) {
|
|
|
|
|
zui_begin_sticky();
|
|
|
|
|
zui_row([1 / 4]);
|
|
|
|
|
if (zui_button("Import")) {
|
|
|
|
|
project_import_mesh(false, tab_objects_import_mesh_done);
|
|
|
|
|
}
|
|
|
|
|
zui_end_sticky();
|
|
|
|
|
|
|
|
|
|
if (zui_panel(zui_handle(__ID__, {selected: true}), "Outliner")) {
|
|
|
|
|
// ui.indent();
|
|
|
|
|
ui._y -= zui_ELEMENT_OFFSET(ui);
|
|
|
|
|
|
|
|
|
|
tab_objects_line_counter = 0;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < _scene_root.children.length) {
|
|
|
|
|
let c: object_t = _scene_root.children[i];
|
2024-03-24 10:26:56 +01:00
|
|
|
tab_objects_draw_list(zui_handle(__ID__), c);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ui.unindent();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
if (zui_panel(zui_handle(__ID__, {selected: true}), "Properties")) {
|
2024-03-14 15:31:22 +01:00
|
|
|
// ui.indent();
|
|
|
|
|
|
|
|
|
|
if (context_context_raw.selected_object != null) {
|
2024-03-24 10:26:56 +01:00
|
|
|
let h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.selected = context_context_raw.selected_object.visible;
|
|
|
|
|
context_context_raw.selected_object.visible = zui_check(h, "Visible");
|
|
|
|
|
|
|
|
|
|
let t = context_context_raw.selected_object.transform;
|
2024-03-20 16:13:54 +01:00
|
|
|
let local_pos = t.loc;
|
2024-03-14 15:31:22 +01:00
|
|
|
let scale = t.scale;
|
|
|
|
|
let rot = quat_get_euler(t.rot);
|
|
|
|
|
let dim = t.dim;
|
|
|
|
|
vec4_mult(rot, 180 / 3.141592);
|
2024-03-20 16:13:54 +01:00
|
|
|
let f: f32 = 0.0;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
|
|
|
|
|
zui_text("Loc");
|
|
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-20 16:13:54 +01:00
|
|
|
h.text = roundfp(local_pos.x) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "X"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
local_pos.x = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-20 16:13:54 +01:00
|
|
|
h.text = roundfp(local_pos.y) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Y"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
local_pos.y = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-20 16:13:54 +01:00
|
|
|
h.text = roundfp(local_pos.z) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Z"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
local_pos.z = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
|
|
|
|
|
zui_text("Rotation");
|
|
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(rot.x) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "X"));
|
2024-03-14 15:31:22 +01:00
|
|
|
let changed = false;
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
changed = true;
|
|
|
|
|
rot.x = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(rot.y) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Y"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
changed = true;
|
|
|
|
|
rot.y = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(rot.z) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Z"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
changed = true;
|
|
|
|
|
rot.z = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
if (changed && context_context_raw.selected_object.name != "Scene") {
|
|
|
|
|
vec4_mult(rot, 3.141592 / 180);
|
|
|
|
|
quat_from_euler(context_context_raw.selected_object.transform.rot, rot.x, rot.y, rot.z);
|
|
|
|
|
transform_build_matrix(context_context_raw.selected_object.transform);
|
|
|
|
|
// ///if arm_physics
|
|
|
|
|
// if (rb != null) rb.syncTransform();
|
|
|
|
|
// ///end
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
|
|
|
|
|
zui_text("Scale");
|
|
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(scale.x) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "X"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
scale.x = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(scale.y) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Y"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
scale.y = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(scale.z) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Z"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
scale.z = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
|
|
|
|
|
zui_text("Dimensions");
|
|
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(dim.x) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "X"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
dim.x = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(dim.y) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Y"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
dim.y = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-03-24 10:26:56 +01:00
|
|
|
h = zui_handle(__ID__);
|
2024-03-14 15:31:22 +01:00
|
|
|
h.text = roundfp(dim.z) + "";
|
2024-03-21 21:06:41 +01:00
|
|
|
f = parse_float(zui_text_input(h, "Z"));
|
2024-03-20 16:13:54 +01:00
|
|
|
if (h.changed) {
|
|
|
|
|
dim.z = f;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
context_context_raw.selected_object.transform.dirty = true;
|
|
|
|
|
|
|
|
|
|
if (context_context_raw.selected_object.name == "Scene") {
|
|
|
|
|
let p = scene_world;
|
2024-03-24 10:26:56 +01:00
|
|
|
p.strength = zui_slider(zui_handle(__ID__, {value: p.strength}), "Environment", 0.0, 5.0, true);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else if (context_context_raw.selected_object.ext_type == "light_object_t") {
|
|
|
|
|
let light = context_context_raw.selected_object.ext;
|
2024-03-24 10:26:56 +01:00
|
|
|
let light_handle = zui_handle(__ID__);
|
2024-03-20 16:13:54 +01:00
|
|
|
light_handle.value = light.data.strength / 10;
|
|
|
|
|
light.data.strength = zui_slider(light_handle, "Strength", 0.0, 5.0, true) * 10;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else if (context_context_raw.selected_object.ext_type == "camera_object_t") {
|
|
|
|
|
let cam = context_context_raw.selected_object.ext;
|
2024-03-24 10:26:56 +01:00
|
|
|
let fov_handle = zui_handle(__ID__);
|
2024-03-20 16:13:54 +01:00
|
|
|
fov_handle.value = math_floor(cam.data.fov * 100) / 100;
|
|
|
|
|
cam.data.fov = zui_slider(fov_handle, "FoV", 0.3, 2.0, true);
|
|
|
|
|
if (fov_handle.changed) {
|
2024-03-14 15:31:22 +01:00
|
|
|
camera_object_build_proj(cam);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ui.unindent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|