From ec1bbdcd539fe1729a05e00adb7b673271c3a2b7 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Wed, 26 Jun 2024 12:29:47 +0700 Subject: [PATCH] - [3D Obj] Fix loaded solid missing alpha value. --- scripts/node_3d_mesh_obj/node_3d_mesh_obj.gml | 19 +++++----- .../node_3d_mesh_stack_slice.gml | 19 +++++++--- .../node_sprite_stack/node_sprite_stack.gml | 13 +++---- scripts/obj_reader/obj_reader.gml | 36 ++++++++++++------- scripts/panel_inspector/panel_inspector.gml | 4 +-- scripts/panel_preview/panel_preview.gml | 4 --- 6 files changed, 58 insertions(+), 37 deletions(-) diff --git a/scripts/node_3d_mesh_obj/node_3d_mesh_obj.gml b/scripts/node_3d_mesh_obj/node_3d_mesh_obj.gml index b82221c48..65d59fe1e 100644 --- a/scripts/node_3d_mesh_obj/node_3d_mesh_obj.gml +++ b/scripts/node_3d_mesh_obj/node_3d_mesh_obj.gml @@ -35,7 +35,8 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) inputs[| in_mesh + 2] = nodeValue("Import Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1) .rejectArray(); - inputs[| in_mesh + 3] = nodeValue("Invert Y", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true) + inputs[| in_mesh + 3] = nodeValue("Swap YZ", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_button, [ "YZ", "Z-Y", "-ZY" ]) .rejectArray(); input_display_list = [ @@ -99,7 +100,7 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) } else { var sol = nodeBuild("Node_Solid", x - (w + 128), matY + m_index * (128 + 32)); sol.name = mat.name + " texture"; - sol.inputs[| 1].setValue(mat.diff); + sol.inputs[| 1].setValue(cola(mat.diff)); inputs[| index].setFrom(sol.outputs[| 0]); } @@ -131,13 +132,13 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) use_display_list = true; if(obj_raw == noone) return; - // var txt = $"========== OBJ import ==========\n"; - // txt += $"Vertex counts: {obj_raw.vertex_count}\n"; - // txt += $"Object counts: {obj_raw.object_counts}\n"; - // txt += $"Material counts: {array_length(obj_raw.materials)}\n"; - // txt += $"Model BBOX: {obj_raw.model_size}\n"; - // txt += $"Load completed in {(get_timer() - obj_read_time) / 1000} ms\n"; - // print(txt); + var txt = $"========== OBJ import ==========\n"; + txt += $"Vertex counts: {obj_raw.vertex_count}\n"; + txt += $"Object counts: {obj_raw.object_counts}\n"; + txt += $"Material counts: {array_length(obj_raw.materials)}\n"; + txt += $"Model BBOX: {obj_raw.model_size}\n"; + txt += $"Load completed in {(get_timer() - obj_read_time) / 1000} ms\n"; + logNode(txt); var span = max(abs(obj_raw.model_size.x), abs(obj_raw.model_size.y), abs(obj_raw.model_size.z)); if(span > 10) { diff --git a/scripts/node_3d_mesh_stack_slice/node_3d_mesh_stack_slice.gml b/scripts/node_3d_mesh_stack_slice/node_3d_mesh_stack_slice.gml index 269702455..bbea0ca00 100644 --- a/scripts/node_3d_mesh_stack_slice/node_3d_mesh_stack_slice.gml +++ b/scripts/node_3d_mesh_stack_slice/node_3d_mesh_stack_slice.gml @@ -83,6 +83,8 @@ function Node_3D_Mesh_Stack_Slice(_x, _y, _group = noone) : Node(_x, _y, _group) var _surfBuff = buffer_from_surface(_matSurf, false); var _surfW = surface_get_width(_matSurf); var _surfH = surface_get_height(_matSurf); + + // print($"{_matSurf} : {_surfBuff} [{buffer_get_size(_surfBuff)}]"); } switch(_mesh.VF) { @@ -128,7 +130,12 @@ function Node_3D_Mesh_Stack_Slice(_x, _y, _group = noone) : Node(_x, _y, _group) faces_maxz = max(faces_maxz, _pz); if(_pid == 9) { - _pnt[9] = _useSurf? buffer_read_at(_surfBuff, (round(_vv * _surfH) * _surfW + round(_uu * _surfW)) * 4, buffer_u32) : c_white; + _uu = frac(_uu) < 0? 1 + frac(_uu) : frac(_uu); + _vv = frac(_vv) < 0? 1 + frac(_vv) : frac(_vv); + var _uvPx = round(_vv * (_surfH - 1)) * _surfW + round(_uu * (_surfW - 1)); + // print($"{_uvPx} : {_uu}, {_vv}"); + + _pnt[9] = _useSurf? buffer_read_at(_surfBuff, _uvPx * 4, buffer_u32) : c_white; _pnt[10] = max(_pnt[0], _pnt[3], _pnt[6]); _pnt[11] = (_pnt[0] + _pnt[3] + _pnt[6]) / 3; @@ -149,6 +156,12 @@ function Node_3D_Mesh_Stack_Slice(_x, _y, _group = noone) : Node(_x, _y, _group) if(_useSurf) buffer_delete(_surfBuff); } + var _ranx = faces_maxx - faces_minx; + var _rany = faces_maxy - faces_miny; + var _ranz = faces_maxz - faces_minz; + + mesh_data.text = $"Faces: {_ind}\nSize: [{_ranx}, {_rany}, {_ranz}]"; + array_sort(_fac, function(a1, a2) { return sign(a2[10] - a1[10]); }); faces_amo = _ind; @@ -197,8 +210,6 @@ function Node_3D_Mesh_Stack_Slice(_x, _y, _group = noone) : Node(_x, _y, _group) var _rany = faces_maxy - faces_miny; var _ranz = faces_maxz - faces_minz; - mesh_data.text = $"Faces: {_faces}\nSize: [{_ranx}, {_rany}, {_ranz}]"; - var _stpx = _ranx / dimensions[0]; var _stpy = _rany / dimensions[1]; var _stpz = _ranz / slicesAmo; @@ -311,7 +322,7 @@ function Node_3D_Mesh_Stack_Slice(_x, _y, _group = noone) : Node(_x, _y, _group) } static update = function() { - + meshInit(); } static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { diff --git a/scripts/node_sprite_stack/node_sprite_stack.gml b/scripts/node_sprite_stack/node_sprite_stack.gml index 45a00fc9a..7fff4e0e9 100644 --- a/scripts/node_sprite_stack/node_sprite_stack.gml +++ b/scripts/node_sprite_stack/node_sprite_stack.gml @@ -62,9 +62,9 @@ function Node_Sprite_Stack(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro var px = _x + pos[0] * _s; var py = _y + pos[1] * _s; - var a = inputs[| 3].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny, THEME.anchor); active &= a; - var a = inputs[| 4].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); active &= a; - var a = inputs[| 5].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); active &= a; + var a = inputs[| 3].drawOverlay(hover, active, px, py, _s * 4, _mx, _my, _snx, _sny, THEME.anchor); active &= a; + var a = inputs[| 4].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); active &= a; + var a = inputs[| 5].drawOverlay(hover, active, px, py, _s, _mx, _my, _snx, _sny); active &= a; } #endregion static drawPreviewToolOverlay = function(hover, active, _mx, _my, _panel) { #region @@ -94,7 +94,6 @@ function Node_Sprite_Stack(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro draw_surface_ext_safe(_s, _sx, _sy, _ss, _ss); if(hover && point_in_rectangle(_mx, _my, _sx - ui(4), _sy, _sx + _sw * _ss + ui(4), _sy + _sh * _ss)) { - hov = true; preview_custom_index = i; draw_set_color(COLORS._main_accent); @@ -103,12 +102,14 @@ function Node_Sprite_Stack(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro draw_rectangle(_sx, _sy, _sx + _sw * _ss, _sy + _sh * _ss, true); - sx += prev_size + ui(8); - preview_custom_x_max += prev_size + ui(8); + sx += _sw * _ss + ui(8); + preview_custom_x_max += _sw * _ss + ui(8); } preview_custom_x_max = max(preview_custom_x_max - _panel.w + ui(64), 0); + var hov = hover && point_in_rectangle(_mx, _my, 0, sy, _panel.x1, _panel.x1); + if(hov) { if(mouse_wheel_down()) preview_custom_x_to -= ui(128); if(mouse_wheel_up()) preview_custom_x_to += ui(128); diff --git a/scripts/obj_reader/obj_reader.gml b/scripts/obj_reader/obj_reader.gml index 14d95fc4a..5d27469d2 100644 --- a/scripts/obj_reader/obj_reader.gml +++ b/scripts/obj_reader/obj_reader.gml @@ -40,18 +40,30 @@ function readObj_file() { switch(sep[0]) { case "v" : - if(obj_reading_yneg) { - array_push(v, [ - real(sep[1]) * obj_reading_scale, - real(sep[3]) * obj_reading_scale, - -real(sep[2]) * obj_reading_scale, - ]); - } else { - array_push(v, [ - real(sep[1]) * obj_reading_scale, - real(sep[2]) * obj_reading_scale, - real(sep[3]) * obj_reading_scale, - ]); + switch(obj_reading_yneg) { + case 0 : + array_push(v, [ + real(sep[1]) * obj_reading_scale, + real(sep[2]) * obj_reading_scale, + real(sep[3]) * obj_reading_scale, + ]); + break; + + case 1 : + array_push(v, [ + real(sep[1]) * obj_reading_scale, + real(sep[3]) * obj_reading_scale, + -real(sep[2]) * obj_reading_scale, + ]); + break; + + case 2 : + array_push(v, [ + real(sep[1]) * obj_reading_scale, + -real(sep[3]) * obj_reading_scale, + real(sep[2]) * obj_reading_scale, + ]); + break; } break; diff --git a/scripts/panel_inspector/panel_inspector.gml b/scripts/panel_inspector/panel_inspector.gml index 6f3ff57e3..b13c2bfc6 100644 --- a/scripts/panel_inspector/panel_inspector.gml +++ b/scripts/panel_inspector/panel_inspector.gml @@ -568,10 +568,10 @@ function Panel_Inspector() : PanelContent() constructor { var con_w = contentPane.surface_w; var con_h = contentPane.surface_h - yy; - draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, 0, yy, con_w, con_h, COLORS._main_icon); + draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, 0, yy, con_w, con_h, merge_color(CDEF.main_ltgrey, CDEF.main_white, 0.5)); yy += ui(8); - for (var i = 0, n = array_length(_logs); i < n; i++) { + for (var i = array_length(_logs) - 1; i >= 0; i--) { var _log = _logs[i]; var _time = _log[0]; diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index 0a75bdc12..958e1625e 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -214,10 +214,6 @@ function Panel_Preview() : PanelContent() constructor { d3_tool_snap_rotation = 15; #endregion - #region shadow map - - #endregion - #region view channel d3ChannelNames = [ "Rendered", "Normal", "Depth" ]; d3Channel = new scrollBox(d3ChannelNames, function(index) { d3_preview_channel = index; });