diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index da770dce5..210c3c4d8 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -312,6 +312,7 @@ {"name":"s_node_gradient_data","order":17,"path":"sprites/s_node_gradient_data/s_node_gradient_data.yy",}, {"name":"s_node_vfx_render","order":1,"path":"sprites/s_node_vfx_render/s_node_vfx_render.yy",}, {"name":"node_stack","order":2,"path":"scripts/node_stack/node_stack.yy",}, + {"name":"sh_draw_r32","order":11,"path":"shaders/sh_draw_r32/sh_draw_r32.yy",}, {"name":"s_node_rigidSim_object","order":3,"path":"sprites/s_node_rigidSim_object/s_node_rigidSim_object.yy",}, {"name":"sh_blend_max","order":8,"path":"shaders/sh_blend_max/sh_blend_max.yy",}, {"name":"s_node_color_out","order":6,"path":"sprites/s_node_color_out/s_node_color_out.yy",}, @@ -413,6 +414,7 @@ {"name":"s_node_noise_perlin","order":11,"path":"sprites/s_node_noise_perlin/s_node_noise_perlin.yy",}, {"name":"sh_d3d_default","order":11,"path":"shaders/sh_d3d_default/sh_d3d_default.yy",}, {"name":"s_node_dithering","order":21,"path":"sprites/s_node_dithering/s_node_dithering.yy",}, + {"name":"node_3d_mesh_extrude","order":8,"path":"scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.yy",}, {"name":"s_workshop_badge","order":1,"path":"sprites/s_workshop_badge/s_workshop_badge.yy",}, {"name":"node_pb_fx_brick","order":12,"path":"scripts/node_pb_fx_brick/node_pb_fx_brick.yy",}, {"name":"node_compare","order":16,"path":"scripts/node_compare/node_compare.yy",}, @@ -991,6 +993,7 @@ {"name":"o_main","order":1,"path":"objects/o_main/o_main.yy",}, {"name":"area_function","order":2,"path":"scripts/area_function/area_function.yy",}, {"name":"__node_3d_mesh","order":1,"path":"scripts/__node_3d_mesh/__node_3d_mesh.yy",}, + {"name":"d3d_surface_extrude","order":7,"path":"scripts/d3d_surface_extrude/d3d_surface_extrude.yy",}, {"name":"node_mesh_to_path","order":3,"path":"scripts/node_mesh_to_path/node_mesh_to_path.yy",}, {"name":"sh_convolution","order":44,"path":"shaders/sh_convolution/sh_convolution.yy",}, {"name":"number_function","order":14,"path":"scripts/number_function/number_function.yy",}, @@ -1043,8 +1046,10 @@ {"name":"node_text","order":5,"path":"scripts/node_text/node_text.yy",}, {"name":"panel_collection","order":3,"path":"scripts/panel_collection/panel_collection.yy",}, {"name":"node_string_trim","order":4,"path":"scripts/node_string_trim/node_string_trim.yy",}, + {"name":"d3d_material","order":12,"path":"scripts/d3d_material/d3d_material.yy",}, {"name":"lerp_float","order":1,"path":"scripts/lerp_float/lerp_float.yy",}, {"name":"vectorRangeBox","order":19,"path":"scripts/vectorRangeBox/vectorRangeBox.yy",}, + {"name":"sh_draw_r8","order":9,"path":"shaders/sh_draw_r8/sh_draw_r8.yy",}, {"name":"s_node_pb_fx_outline","order":5,"path":"sprites/s_node_pb_fx_outline/s_node_pb_fx_outline.yy",}, {"name":"fd_rectangle_get_velocity_width","order":26,"path":"scripts/fd_rectangle_get_velocity_width/fd_rectangle_get_velocity_width.yy",}, {"name":"node_convolution","order":5,"path":"scripts/node_convolution/node_convolution.yy",}, @@ -1408,6 +1413,7 @@ {"name":"s_node_group_output","order":15,"path":"sprites/s_node_group_output/s_node_group_output.yy",}, {"name":"node_path_l_system","order":10,"path":"scripts/node_path_l_system/node_path_l_system.yy",}, {"name":"panel_gradient","order":2,"path":"scripts/panel_gradient/panel_gradient.yy",}, + {"name":"sh_draw_r16","order":10,"path":"shaders/sh_draw_r16/sh_draw_r16.yy",}, {"name":"sh_channel_S","order":5,"path":"shaders/sh_channel_S/sh_channel_S.yy",}, {"name":"string_scale","order":4,"path":"scripts/string_scale/string_scale.yy",}, {"name":"s_node_cache","order":27,"path":"sprites/s_node_cache/s_node_cache.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index 4bb4798c8..84d0dc316 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -845,6 +845,7 @@ {"id":{"name":"s_node_vfx_render","path":"sprites/s_node_vfx_render/s_node_vfx_render.yy",},}, {"id":{"name":"node_stack","path":"scripts/node_stack/node_stack.yy",},}, {"id":{"name":"sh_cell_noise","path":"shaders/sh_cell_noise/sh_cell_noise.yy",},}, + {"id":{"name":"sh_draw_r32","path":"shaders/sh_draw_r32/sh_draw_r32.yy",},}, {"id":{"name":"s_node_rigidSim_object","path":"sprites/s_node_rigidSim_object/s_node_rigidSim_object.yy",},}, {"id":{"name":"sh_blend_max","path":"shaders/sh_blend_max/sh_blend_max.yy",},}, {"id":{"name":"s_node_color_out","path":"sprites/s_node_color_out/s_node_color_out.yy",},}, @@ -957,6 +958,7 @@ {"id":{"name":"s_node_noise_perlin","path":"sprites/s_node_noise_perlin/s_node_noise_perlin.yy",},}, {"id":{"name":"sh_d3d_default","path":"shaders/sh_d3d_default/sh_d3d_default.yy",},}, {"id":{"name":"s_node_dithering","path":"sprites/s_node_dithering/s_node_dithering.yy",},}, + {"id":{"name":"node_3d_mesh_extrude","path":"scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.yy",},}, {"id":{"name":"s_node_boolean","path":"sprites/s_node_boolean/s_node_boolean.yy",},}, {"id":{"name":"s_workshop_badge","path":"sprites/s_workshop_badge/s_workshop_badge.yy",},}, {"id":{"name":"node_pb_fx_brick","path":"scripts/node_pb_fx_brick/node_pb_fx_brick.yy",},}, @@ -1613,6 +1615,7 @@ {"id":{"name":"o_main","path":"objects/o_main/o_main.yy",},}, {"id":{"name":"area_function","path":"scripts/area_function/area_function.yy",},}, {"id":{"name":"__node_3d_mesh","path":"scripts/__node_3d_mesh/__node_3d_mesh.yy",},}, + {"id":{"name":"d3d_surface_extrude","path":"scripts/d3d_surface_extrude/d3d_surface_extrude.yy",},}, {"id":{"name":"node_mesh_to_path","path":"scripts/node_mesh_to_path/node_mesh_to_path.yy",},}, {"id":{"name":"node_fluid_sim","path":"scripts/node_fluid_sim/node_fluid_sim.yy",},}, {"id":{"name":"sh_convolution","path":"shaders/sh_convolution/sh_convolution.yy",},}, @@ -1670,8 +1673,10 @@ {"id":{"name":"panel_collection","path":"scripts/panel_collection/panel_collection.yy",},}, {"id":{"name":"contextMenu_controller","path":"scripts/contextMenu_controller/contextMenu_controller.yy",},}, {"id":{"name":"node_string_trim","path":"scripts/node_string_trim/node_string_trim.yy",},}, + {"id":{"name":"d3d_material","path":"scripts/d3d_material/d3d_material.yy",},}, {"id":{"name":"lerp_float","path":"scripts/lerp_float/lerp_float.yy",},}, {"id":{"name":"vectorRangeBox","path":"scripts/vectorRangeBox/vectorRangeBox.yy",},}, + {"id":{"name":"sh_draw_r8","path":"shaders/sh_draw_r8/sh_draw_r8.yy",},}, {"id":{"name":"s_node_pb_fx_outline","path":"sprites/s_node_pb_fx_outline/s_node_pb_fx_outline.yy",},}, {"id":{"name":"sh_draw_vertex_aa","path":"shaders/sh_draw_vertex_aa/sh_draw_vertex_aa.yy",},}, {"id":{"name":"fd_rectangle_get_velocity_width","path":"scripts/fd_rectangle_get_velocity_width/fd_rectangle_get_velocity_width.yy",},}, @@ -2097,6 +2102,7 @@ {"id":{"name":"s_node_group_output","path":"sprites/s_node_group_output/s_node_group_output.yy",},}, {"id":{"name":"node_path_l_system","path":"scripts/node_path_l_system/node_path_l_system.yy",},}, {"id":{"name":"panel_gradient","path":"scripts/panel_gradient/panel_gradient.yy",},}, + {"id":{"name":"sh_draw_r16","path":"shaders/sh_draw_r16/sh_draw_r16.yy",},}, {"id":{"name":"sh_channel_S","path":"shaders/sh_channel_S/sh_channel_S.yy",},}, {"id":{"name":"string_scale","path":"scripts/string_scale/string_scale.yy",},}, {"id":{"name":"s_node_cache","path":"sprites/s_node_cache/s_node_cache.yy",},}, diff --git a/objects/o_dialog_preview_3d_settings/Create_0.gml b/objects/o_dialog_preview_3d_settings/Create_0.gml index 19ad09ddb..07b16e0eb 100644 --- a/objects/o_dialog_preview_3d_settings/Create_0.gml +++ b/objects/o_dialog_preview_3d_settings/Create_0.gml @@ -2,7 +2,7 @@ event_inherited(); #region data - dialog_w = ui(320); + dialog_w = ui(400); destroy_on_click_out = true; preview_panel = noone; @@ -35,6 +35,26 @@ event_inherited(); __txt("Shadow"), function() { return preview_panel.d3_scene_light0.shadow_active }, ], + [ + new vectorBox(2, function(index, value) { + if(index == 0) preview_panel.d3_view_camera.view_near = value; + else if(index == 1) preview_panel.d3_view_camera.view_far = value; + }), + __txt("View Plane"), + function() { return [ preview_panel.d3_view_camera.view_near, preview_panel.d3_view_camera.view_far ] }, + ], + [ + new checkBox(function() { + preview_panel.d3_scene.gammaCorrection = !preview_panel.d3_scene.gammaCorrection; }), + __txt("Gamma Correct"), + function() { return preview_panel.d3_scene.gammaCorrection }, + ], + [ + new checkBox(function() { + preview_panel.d3_scene.show_normal = !preview_panel.d3_scene.show_normal; }), + __txt("Normal"), + function() { return preview_panel.d3_scene.show_normal }, + ], ] dialog_h = ui(60 + 40 * array_length(properties)); diff --git a/objects/o_dialog_preview_3d_settings/Draw_64.gml b/objects/o_dialog_preview_3d_settings/Draw_64.gml index f547596d8..144b6c811 100644 --- a/objects/o_dialog_preview_3d_settings/Draw_64.gml +++ b/objects/o_dialog_preview_3d_settings/Draw_64.gml @@ -12,7 +12,7 @@ if !ready exit; #region draw var yy = dialog_y + ui(64); - var ww = ui(128); + var ww = ui(200); var wh = TEXTBOX_HEIGHT; for( var i = 0, n = array_length(properties); i < n; i++ ) { diff --git a/scripts/__node_3d_object/__node_3d_object.gml b/scripts/__node_3d_object/__node_3d_object.gml index c91c1ca19..4067c68e0 100644 --- a/scripts/__node_3d_object/__node_3d_object.gml +++ b/scripts/__node_3d_object/__node_3d_object.gml @@ -385,6 +385,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr } #endregion static drawGizmoScale = function(index, object, _vpos, active, params, _mx, _my, _snx, _sny, _panel) { #region + tool_attribute.context = 0; #region ---- main ---- var _sca = inputs[| index].getValue(,,, true); var _qrot = object == noone? new BBMOD_Quaternion() : object.rotation; @@ -504,8 +505,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr drag_mx += _mx - drag_px; drag_my += _my - drag_py; - var mAdj, nor; - + var mAdj, nor, prj; var ray = _camera.viewPointToWorldRay(drag_mx, drag_my); if(drag_axis < 3) { @@ -516,7 +516,6 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr } nor = _qrot.Rotate(nor); - prj = _qrot.Rotate(prj); var pln = new __plane(drag_original, nor); mAdj = d3d_intersect_ray_plane(ray, pln); @@ -525,8 +524,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr var _diff = mAdj.subtract(drag_prev); var _dist = _diff.dot(prj); - for( var i = 0; i < 3; i++ ) - drag_val[i] += prj.getIndex(i) * _dist; + drag_val[drag_axis] += prj.getIndex(drag_axis) * _dist; if(inputs[| index].setValue(value_snap(drag_val, _snx))) UNDO_HOLDING = true; @@ -607,15 +605,13 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr return object; } #endregion - static newObject = function() { return object_class == noone? noone : new object_class(); } - static getObject = function(index, class = object_class) { #region var _obj = array_safe_get(cached_object, index, noone); if(_obj == noone) { - _obj = newObject(); + _obj = new class(); } else if(!is_instanceof(_obj, class)) { _obj.destroy(); - _obj = newObject(); + _obj = new class(); } cached_object[index] = _obj; diff --git a/scripts/d3d_camera/d3d_camera.gml b/scripts/d3d_camera/d3d_camera.gml index 18527a275..6d90bef6a 100644 --- a/scripts/d3d_camera/d3d_camera.gml +++ b/scripts/d3d_camera/d3d_camera.gml @@ -20,7 +20,7 @@ function __3dCamera() constructor { fov = 60; view_near = .01; - view_far = 100; + view_far = 10; view_w = 1; view_h = 1; @@ -43,8 +43,11 @@ function __3dCamera() constructor { } static applyCamera = function() { - camera_set_proj_mat(raw, projMat.raw); camera_set_view_mat(raw, viewMat.raw); + camera_set_proj_mat(raw, projMat.raw); + + var _viewMat = viewMat.transpose(); + var _projMat = projMat.transpose(); camera_apply(raw); } @@ -57,11 +60,8 @@ function __3dCamera() constructor { static setMatrix = function() { if(projection == CAMERA_PROJECTION.perspective) projMat.setRaw(matrix_build_projection_perspective_fov(fov, view_aspect, view_near, view_far)); - else { + else projMat.setRaw(matrix_build_projection_ortho(view_w, view_h, view_near, view_far)); - //print($"{view_w}, {view_h}, {view_near}, {view_far}") - //print(projMat); - } if(useFocus) viewMat.setRaw(matrix_build_lookat(position.x, position.y, position.z, focus.x, focus.y, focus.z, up.x, up.y, up.z)); diff --git a/scripts/d3d_camera_object/d3d_camera_object.gml b/scripts/d3d_camera_object/d3d_camera_object.gml index ed4e0bdda..494785a52 100644 --- a/scripts/d3d_camera_object/d3d_camera_object.gml +++ b/scripts/d3d_camera_object/d3d_camera_object.gml @@ -5,7 +5,7 @@ function __3dCamera_object() : __3dObject() constructor { ovh = 0.5; //outerViewHeight len = 0.5; //cameraLength - vertex = [ + vertex = [[ V3( -len, -ivw, ivh ), V3( -len, ivw, ivh ), V3( -len, ivw, ivh ), V3( -len, ivw, -ivh ), V3( -len, ivw, -ivh ), V3( -len, -ivw, -ivh ), @@ -24,7 +24,7 @@ function __3dCamera_object() : __3dObject() constructor { V3( len, -ovw * 0.5, ovh + 0.2 ), V3( len, ovw * 0.5, ovh + 0.2 ), V3( len, 0, ovh + 0.6 ), V3( len, ovw * 0.5, ovh + 0.2 ), V3( len, -ovw * 0.5, ovh + 0.2 ), V3( len, 0, ovh + 0.6 ), - ]; + ]]; VF = global.VF_POS_COL; render_type = pr_linelist; diff --git a/scripts/d3d_cone/d3d_cone.gml b/scripts/d3d_cone/d3d_cone.gml index 4c7e0244f..e4eb82b4e 100644 --- a/scripts/d3d_cone/d3d_cone.gml +++ b/scripts/d3d_cone/d3d_cone.gml @@ -29,8 +29,8 @@ function __3dCone(radius = 0.5, height = 1, sides = 8, smooth = false) : __3dObj var _v1 = 0.5 + lengthdir_y(0.5, a1); v0[i * 3 + 0] = V3( 0, 0, -_h).setNormal(0, 0, -1).setUV(0.5, 0.5); - v0[i * 3 + 1] = V3(x0, y0, -_h).setNormal(0, 0, -1).setUV(_u0, _v0); - v0[i * 3 + 2] = V3(x1, y1, -_h).setNormal(0, 0, -1).setUV(_u1, _v1); + v0[i * 3 + 1] = V3(x1, y1, -_h).setNormal(0, 0, -1).setUV(_u1, _v1); + v0[i * 3 + 2] = V3(x0, y0, -_h).setNormal(0, 0, -1).setUV(_u0, _v0); } for( var i = 0; i < sides; i++ ) { @@ -61,8 +61,9 @@ function __3dCone(radius = 0.5, height = 1, sides = 8, smooth = false) : __3dObj } vertex = [ v0, vs ]; - + VB = build(); + generateNormal(); } initModel(); static onParameterUpdate = initModel; diff --git a/scripts/d3d_cube/d3d_cube.gml b/scripts/d3d_cube/d3d_cube.gml index dfaf75f3c..5ecd86eee 100644 --- a/scripts/d3d_cube/d3d_cube.gml +++ b/scripts/d3d_cube/d3d_cube.gml @@ -5,68 +5,62 @@ function __3dCube() : __3dObject() constructor { static initModel = function(size) { size /= 2; - vertex = [ - V3(-size, -size, size), V3(size, -size, size), V3(size, size, size), - V3(-size, -size, size), V3(size, size, size), V3(-size, size, size), + vertex = [[ + V3(-size, -size, size).setNormal(0, 0, 1).setUV(0, 0), + V3( size, size, size).setNormal(0, 0, 1).setUV(1, 0), + V3( size, -size, size).setNormal(0, 0, 1).setUV(1, 1), + + V3(-size, -size, size).setNormal(0, 0, 1).setUV(0, 0), + V3(-size, size, size).setNormal(0, 0, 1).setUV(1, 1), + V3( size, size, size).setNormal(0, 0, 1).setUV(0, 1), - V3(-size, -size, -size), V3(size, -size, -size), V3(size, size, -size), - V3(-size, -size, -size), V3(size, size, -size), V3(-size, size, -size), + + V3(-size, -size, -size).setNormal(0, 0, -1).setUV(0, 0), + V3( size, -size, -size).setNormal(0, 0, -1).setUV(1, 0), + V3( size, size, -size).setNormal(0, 0, -1).setUV(1, 1), + + V3(-size, -size, -size).setNormal(0, 0, -1).setUV(0, 0), + V3( size, size, -size).setNormal(0, 0, -1).setUV(1, 1), + V3(-size, size, -size).setNormal(0, 0, -1).setUV(0, 1), + + + V3(-size, -size, size).setNormal(-1, 0, 0).setUV(0, 0), + V3(-size, size, -size).setNormal(-1, 0, 0).setUV(1, 0), + V3(-size, size, size).setNormal(-1, 0, 0).setUV(1, 1), + + V3(-size, -size, size).setNormal(-1, 0, 0).setUV(0, 0), + V3(-size, -size, -size).setNormal(-1, 0, 0).setUV(1, 1), + V3(-size, size, -size).setNormal(-1, 0, 0).setUV(0, 1), + + + V3( size, -size, size).setNormal(1, 0, 0).setUV(0, 0), + V3( size, size, size).setNormal(1, 0, 0).setUV(1, 0), + V3( size, size, -size).setNormal(1, 0, 0).setUV(1, 1), + + V3( size, -size, size).setNormal(1, 0, 0).setUV(0, 0), + V3( size, size, -size).setNormal(1, 0, 0).setUV(1, 1), + V3( size, -size, -size).setNormal(1, 0, 0).setUV(0, 1), + + + V3(-size, size, size).setNormal(0, 1, 0).setUV(0, 0), + V3( size, size, -size).setNormal(0, 1, 0).setUV(1, 0), + V3( size, size, size).setNormal(0, 1, 0).setUV(1, 1), + + V3(-size, size, size).setNormal(0, 1, 0).setUV(0, 0), + V3(-size, size, -size).setNormal(0, 1, 0).setUV(1, 1), + V3( size, size, -size).setNormal(0, 1, 0).setUV(0, 1), - V3(-size, -size, size), V3(-size, size, size), V3(-size, size, -size), - V3(-size, -size, size), V3(-size, size, -size), V3(-size, -size, -size), - - V3(size, -size, size), V3(size, size, size), V3(size, size, -size), - V3(size, -size, size), V3(size, size, -size), V3(size, -size, -size), - - V3(-size, size, size), V3(size, size, size), V3(size, size, -size), - V3(-size, size, size), V3(size, size, -size), V3(-size, size, -size), - - V3(-size, -size, size), V3(size, -size, size), V3(size, -size, -size), - V3(-size, -size, size), V3(size, -size, -size), V3(-size, -size, -size) - ]; - - normals = [ - [0, 0, 1], [0, 0, 1], [0, 0, 1], - [0, 0, 1], [0, 0, 1], [0, 0, 1], - - [0, 0, -1], [0, 0, -1], [0, 0, -1], - [0, 0, -1], [0, 0, -1], [0, 0, -1], - - [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], - [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], - - [1, 0, 0], [1, 0, 0], [1, 0, 0], - [1, 0, 0], [1, 0, 0], [1, 0, 0], - - [0, 1, 0], [0, 1, 0], [0, 1, 0], - [0, 1, 0], [0, 1, 0], [0, 1, 0], - - [0, -1, 0], [0, -1, 0], [0, -1, 0], - [0, -1, 0], [0, -1, 0], [0, -1, 0] - ]; - - uv = [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1] - ]; - - array_foreach(vertex, function(val, ind) { val.setNormal(normals[ind]); val.setUV(uv[ind]); }) + + V3(-size, -size, size).setNormal(0, -1, 0).setUV(0, 0), + V3( size, -size, size).setNormal(0, -1, 0).setUV(1, 0), + V3( size, -size, -size).setNormal(0, -1, 0).setUV(1, 1), + + V3(-size, -size, size).setNormal(0, -1, 0).setUV(0, 0), + V3( size, -size, -size).setNormal(0, -1, 0).setUV(1, 1), + V3(-size, -size, -size).setNormal(0, -1, 0).setUV(0, 1), + ]]; VB = build(); + generateNormal(); } initModel(1); } \ No newline at end of file diff --git a/scripts/d3d_cube_faces/d3d_cube_faces.gml b/scripts/d3d_cube_faces/d3d_cube_faces.gml index 609fe9be1..44559f2a5 100644 --- a/scripts/d3d_cube_faces/d3d_cube_faces.gml +++ b/scripts/d3d_cube_faces/d3d_cube_faces.gml @@ -7,93 +7,63 @@ function __3dCubeFaces() : __3dObject() constructor { size /= 2; vertex = [ - [ - V3(-size, -size, size), V3(size, -size, size), V3(size, size, size), - V3(-size, -size, size), V3(size, size, size), V3(-size, size, size), - ], [ - V3(-size, -size, -size), V3(size, -size, -size), V3(size, size, -size), - V3(-size, -size, -size), V3(size, size, -size), V3(-size, size, -size), + V3(-size, -size, size).setNormal(0, 0, 1).setUV(0, 0), + V3( size, size, size).setNormal(0, 0, 1).setUV(1, 0), + V3( size, -size, size).setNormal(0, 0, 1).setUV(1, 1), + + V3(-size, -size, size).setNormal(0, 0, 1).setUV(0, 0), + V3(-size, size, size).setNormal(0, 0, 1).setUV(1, 1), + V3( size, size, size).setNormal(0, 0, 1).setUV(0, 1), ], [ - V3(-size, -size, size), V3(-size, size, size), V3(-size, size, -size), - V3(-size, -size, size), V3(-size, size, -size), V3(-size, -size, -size), + V3(-size, -size, -size).setNormal(0, 0, -1).setUV(0, 0), + V3( size, -size, -size).setNormal(0, 0, -1).setUV(1, 0), + V3( size, size, -size).setNormal(0, 0, -1).setUV(1, 1), + + V3(-size, -size, -size).setNormal(0, 0, -1).setUV(0, 0), + V3( size, size, -size).setNormal(0, 0, -1).setUV(1, 1), + V3(-size, size, -size).setNormal(0, 0, -1).setUV(0, 1), ], - [ - V3(size, -size, size), V3(size, size, size), V3(size, size, -size), - V3(size, -size, size), V3(size, size, -size), V3(size, -size, -size), + [ + V3(-size, -size, size).setNormal(-1, 0, 0).setUV(0, 0), + V3(-size, size, -size).setNormal(-1, 0, 0).setUV(1, 0), + V3(-size, size, size).setNormal(-1, 0, 0).setUV(1, 1), + + V3(-size, -size, size).setNormal(-1, 0, 0).setUV(0, 0), + V3(-size, -size, -size).setNormal(-1, 0, 0).setUV(1, 1), + V3(-size, size, -size).setNormal(-1, 0, 0).setUV(0, 1), ], - [ - V3(-size, size, size), V3(size, size, size), V3(size, size, -size), - V3(-size, size, size), V3(size, size, -size), V3(-size, size, -size), + [ + V3( size, -size, size).setNormal(1, 0, 0).setUV(0, 0), + V3( size, size, size).setNormal(1, 0, 0).setUV(1, 0), + V3( size, size, -size).setNormal(1, 0, 0).setUV(1, 1), + + V3( size, -size, size).setNormal(1, 0, 0).setUV(0, 0), + V3( size, size, -size).setNormal(1, 0, 0).setUV(1, 1), + V3( size, -size, -size).setNormal(1, 0, 0).setUV(0, 1), ], + [ + V3(-size, size, size).setNormal(0, 1, 0).setUV(0, 0), + V3( size, size, -size).setNormal(0, 1, 0).setUV(1, 0), + V3( size, size, size).setNormal(0, 1, 0).setUV(1, 1), + + V3(-size, size, size).setNormal(0, 1, 0).setUV(0, 0), + V3(-size, size, -size).setNormal(0, 1, 0).setUV(1, 1), + V3( size, size, -size).setNormal(0, 1, 0).setUV(0, 1), + ], [ - V3(-size, -size, size), V3(size, -size, size), V3(size, -size, -size), - V3(-size, -size, size), V3(size, -size, -size), V3(-size, -size, -size) - ] - ]; - - normals = [ - [ - [0, 0, 1], [0, 0, 1], [0, 0, 1], - [0, 0, 1], [0, 0, 1], [0, 0, 1], - ], - [ - [0, 0, -1], [0, 0, -1], [0, 0, -1], - [0, 0, -1], [0, 0, -1], [0, 0, -1], - ], - [ - [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], - [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], - ], - [ - [1, 0, 0], [1, 0, 0], [1, 0, 0], - [1, 0, 0], [1, 0, 0], [1, 0, 0], - ], - [ - [0, 1, 0], [0, 1, 0], [0, 1, 0], - [0, 1, 0], [0, 1, 0], [0, 1, 0], - ], - [ - [0, -1, 0], [0, -1, 0], [0, -1, 0], - [0, -1, 0], [0, -1, 0], [0, -1, 0] + V3(-size, -size, size).setNormal(0, -1, 0).setUV(0, 0), + V3( size, -size, size).setNormal(0, -1, 0).setUV(1, 0), + V3( size, -size, -size).setNormal(0, -1, 0).setUV(1, 1), + + V3(-size, -size, size).setNormal(0, -1, 0).setUV(0, 0), + V3( size, -size, -size).setNormal(0, -1, 0).setUV(1, 1), + V3(-size, -size, -size).setNormal(0, -1, 0).setUV(0, 1), ] ]; - uv = [ - [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - ], - [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - ], - [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - ], - [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - ], - [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - ], - [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1] - ] - ]; - - array_foreach(vertex[0], function(val, ind) { val.normal.set(normals[0][ind]); val.uv.set(uv[0][ind]); }) - array_foreach(vertex[1], function(val, ind) { val.normal.set(normals[1][ind]); val.uv.set(uv[1][ind]); }) - array_foreach(vertex[2], function(val, ind) { val.normal.set(normals[2][ind]); val.uv.set(uv[2][ind]); }) - array_foreach(vertex[3], function(val, ind) { val.normal.set(normals[3][ind]); val.uv.set(uv[3][ind]); }) - array_foreach(vertex[4], function(val, ind) { val.normal.set(normals[4][ind]); val.uv.set(uv[4][ind]); }) - array_foreach(vertex[5], function(val, ind) { val.normal.set(normals[5][ind]); val.uv.set(uv[5][ind]); }) - VB = build(); + generateNormal(); } initModel(1); } \ No newline at end of file diff --git a/scripts/d3d_cylinder/d3d_cylinder.gml b/scripts/d3d_cylinder/d3d_cylinder.gml index e4071a18f..f4fb2047e 100644 --- a/scripts/d3d_cylinder/d3d_cylinder.gml +++ b/scripts/d3d_cylinder/d3d_cylinder.gml @@ -33,8 +33,8 @@ function __3dCylinder(radius = 0.5, height = 1, sides = 8, smooth = false) : __3 v0[i * 3 + 2] = V3(x1, y1, _h).setNormal(0, 0, 1).setUV(_u1, _v1); v1[i * 3 + 0] = V3( 0, 0, -_h).setNormal(0, 0, -1).setUV(0.5, 0.5); - v1[i * 3 + 1] = V3(x0, y0, -_h).setNormal(0, 0, -1).setUV(_u0, _v0); - v1[i * 3 + 2] = V3(x1, y1, -_h).setNormal(0, 0, -1).setUV(_u1, _v1); + v1[i * 3 + 1] = V3(x1, y1, -_h).setNormal(0, 0, -1).setUV(_u1, _v1); + v1[i * 3 + 2] = V3(x0, y0, -_h).setNormal(0, 0, -1).setUV(_u0, _v0); } for( var i = 0; i < sides; i++ ) { @@ -55,17 +55,18 @@ function __3dCylinder(radius = 0.5, height = 1, sides = 8, smooth = false) : __3 var ux1 = (i + 1) / sides; vs[i * 3 * 2 + 0] = V3(x0, y0, _h).setNormal(nx0, ny0, 0).setUV(ux0, 0); - vs[i * 3 * 2 + 1] = V3(x1, y1, _h).setNormal(nx1, ny1, 0).setUV(ux1, 0); - vs[i * 3 * 2 + 2] = V3(x0, y0, -_h).setNormal(nx0, ny0, 0).setUV(ux0, 1); + vs[i * 3 * 2 + 1] = V3(x0, y0, -_h).setNormal(nx0, ny0, 0).setUV(ux0, 1); + vs[i * 3 * 2 + 2] = V3(x1, y1, _h).setNormal(nx1, ny1, 0).setUV(ux1, 0); vs[i * 3 * 2 + 3] = V3(x0, y0, -_h).setNormal(nx0, ny0, 0).setUV(ux0, 1); - vs[i * 3 * 2 + 4] = V3(x1, y1, _h).setNormal(nx1, ny1, 0).setUV(ux1, 0); - vs[i * 3 * 2 + 5] = V3(x1, y1, -_h).setNormal(nx1, ny1, 0).setUV(ux1, 1); + vs[i * 3 * 2 + 4] = V3(x1, y1, -_h).setNormal(nx1, ny1, 0).setUV(ux1, 1); + vs[i * 3 * 2 + 5] = V3(x1, y1, _h).setNormal(nx1, ny1, 0).setUV(ux1, 0); } vertex = [ v0, v1, vs ]; VB = build(); + generateNormal(); } initModel(); static onParameterUpdate = initModel; diff --git a/scripts/d3d_gizmo_circle_z/d3d_gizmo_circle_z.gml b/scripts/d3d_gizmo_circle_z/d3d_gizmo_circle_z.gml index ba4243da9..316054806 100644 --- a/scripts/d3d_gizmo_circle_z/d3d_gizmo_circle_z.gml +++ b/scripts/d3d_gizmo_circle_z/d3d_gizmo_circle_z.gml @@ -1,5 +1,5 @@ function __3dGizmoCircleZ(radius = 0.5, color = c_white, alpha = 1) : __3dGizmo() constructor { - vertex = array_create(33 * 2); + vertex = [ array_create(33 * 2) ]; var _i = 0; for( var i = 0; i <= 32; i++ ) { @@ -10,8 +10,8 @@ function __3dGizmoCircleZ(radius = 0.5, color = c_white, alpha = 1) : __3dGizmo( var x1 = lengthdir_x(radius, a1); var y1 = lengthdir_y(radius, a1); - vertex[_i++] = V3( x0, y0, 0, color, alpha ); - vertex[_i++] = V3( x1, y1, 0, color, alpha ); + vertex[0][_i++] = V3( x0, y0, 0, color, alpha ); + vertex[0][_i++] = V3( x1, y1, 0, color, alpha ); } VB = build(); diff --git a/scripts/d3d_gizmo_line/d3d_gizmo_line.gml b/scripts/d3d_gizmo_line/d3d_gizmo_line.gml index 4d2ae1062..1a7bd08f9 100644 --- a/scripts/d3d_gizmo_line/d3d_gizmo_line.gml +++ b/scripts/d3d_gizmo_line/d3d_gizmo_line.gml @@ -1,7 +1,7 @@ function __3dGizmoLine(from, to, color = c_white, alpha = 1) : __3dGizmo() constructor { - vertex = [ + vertex = [[ V3( from.x, from.y, from.z, color, alpha ), V3( to.x, to.y, to.z, color, alpha ), - ]; + ]]; VB = build(); } \ No newline at end of file diff --git a/scripts/d3d_gizmo_line_dashed/d3d_gizmo_line_dashed.gml b/scripts/d3d_gizmo_line_dashed/d3d_gizmo_line_dashed.gml index 6e2d6d5b8..0279c4c92 100644 --- a/scripts/d3d_gizmo_line_dashed/d3d_gizmo_line_dashed.gml +++ b/scripts/d3d_gizmo_line_dashed/d3d_gizmo_line_dashed.gml @@ -2,13 +2,13 @@ function __3dGizmoLineDashed(from, to, dash = 0.1, color = c_white, alpha = 1) : var _dist = from.distance(to); var _dash = max(2, ceil(_dist / dash)); - vertex = array_create(_dash); + vertex = [ array_create(_dash) ]; for( var i = 0; i < _dash; i++ ) { var prog = i / (_dash - 1); - vertex[i] = V3( lerp(from.x, to.x, prog), - lerp(from.y, to.y, prog), - lerp(from.z, to.z, prog), - color, alpha ); + vertex[0][i] = V3( lerp(from.x, to.x, prog), + lerp(from.y, to.y, prog), + lerp(from.z, to.z, prog), + color, alpha ); } VB = build(); } \ No newline at end of file diff --git a/scripts/d3d_gizmo_sphere/d3d_gizmo_sphere.gml b/scripts/d3d_gizmo_sphere/d3d_gizmo_sphere.gml index 43fb0aa99..6706eb9a6 100644 --- a/scripts/d3d_gizmo_sphere/d3d_gizmo_sphere.gml +++ b/scripts/d3d_gizmo_sphere/d3d_gizmo_sphere.gml @@ -1,5 +1,5 @@ function __3dGizmoSphere(radius = 0.5, color = c_white, alpha = 1) : __3dGizmo() constructor { - vertex = array_create(33 * 3); + vertex = [ array_create(33 * 3) ]; var _i = 0; for( var i = 0; i <= 32; i++ ) { @@ -10,12 +10,12 @@ function __3dGizmoSphere(radius = 0.5, color = c_white, alpha = 1) : __3dGizmo() var x1 = lengthdir_x(radius, a1); var y1 = lengthdir_y(radius, a1); - vertex[_i++] = V3( 0, x0, y0, color, alpha ); - vertex[_i++] = V3( 0, x1, y1, color, alpha ); - vertex[_i++] = V3( x0, 0, y0, color, alpha ); - vertex[_i++] = V3( x1, 0, y1, color, alpha ); - vertex[_i++] = V3( x0, y0, 0, color, alpha ); - vertex[_i++] = V3( x1, y1, 0, color, alpha ); + vertex[0][_i++] = V3( 0, x0, y0, color, alpha ); + vertex[0][_i++] = V3( 0, x1, y1, color, alpha ); + vertex[0][_i++] = V3( x0, 0, y0, color, alpha ); + vertex[0][_i++] = V3( x1, 0, y1, color, alpha ); + vertex[0][_i++] = V3( x0, y0, 0, color, alpha ); + vertex[0][_i++] = V3( x1, y1, 0, color, alpha ); } VB = build(); diff --git a/scripts/d3d_icosphere/d3d_icosphere.gml b/scripts/d3d_icosphere/d3d_icosphere.gml index 9df834a8a..08f6598a1 100644 --- a/scripts/d3d_icosphere/d3d_icosphere.gml +++ b/scripts/d3d_icosphere/d3d_icosphere.gml @@ -66,26 +66,26 @@ function __3dICOSphere(radius = 0.5, level = 2, smt = false) : __3dObject() cons array_foreach(icoverts, function(vert) { vert.old = true; }) // Generate icosphere vertices - ds_list_add(_vertices, icoverts[ 3], icoverts[ 2], icoverts[ 1]); - ds_list_add(_vertices, icoverts[ 2], icoverts[ 3], icoverts[ 4]); - ds_list_add(_vertices, icoverts[ 6], icoverts[ 5], icoverts[ 4]); - ds_list_add(_vertices, icoverts[ 5], icoverts[ 9], icoverts[ 4]); - ds_list_add(_vertices, icoverts[ 8], icoverts[ 7], icoverts[ 1]); - ds_list_add(_vertices, icoverts[ 7], icoverts[10], icoverts[ 1]); - ds_list_add(_vertices, icoverts[12], icoverts[11], icoverts[ 5]); - ds_list_add(_vertices, icoverts[11], icoverts[12], icoverts[ 7]); - ds_list_add(_vertices, icoverts[10], icoverts[ 6], icoverts[ 3]); - ds_list_add(_vertices, icoverts[ 6], icoverts[10], icoverts[12]); - ds_list_add(_vertices, icoverts[ 9], icoverts[ 8], icoverts[ 2]); - ds_list_add(_vertices, icoverts[ 8], icoverts[ 9], icoverts[11]); - ds_list_add(_vertices, icoverts[ 3], icoverts[ 6], icoverts[ 4]); - ds_list_add(_vertices, icoverts[ 9], icoverts[ 2], icoverts[ 4]); - ds_list_add(_vertices, icoverts[10], icoverts[ 3], icoverts[ 1]); - ds_list_add(_vertices, icoverts[ 2], icoverts[ 8], icoverts[ 1]); - ds_list_add(_vertices, icoverts[12], icoverts[10], icoverts[ 7]); - ds_list_add(_vertices, icoverts[ 8], icoverts[11], icoverts[ 7]); - ds_list_add(_vertices, icoverts[ 6], icoverts[12], icoverts[ 5]); - ds_list_add(_vertices, icoverts[11], icoverts[ 9], icoverts[ 5]); + ds_list_add(_vertices, icoverts[ 3], icoverts[ 1], icoverts[ 2]); + ds_list_add(_vertices, icoverts[ 2], icoverts[ 4], icoverts[ 3]); + ds_list_add(_vertices, icoverts[ 6], icoverts[ 4], icoverts[ 5]); + ds_list_add(_vertices, icoverts[ 5], icoverts[ 4], icoverts[ 9]); + ds_list_add(_vertices, icoverts[ 8], icoverts[ 1], icoverts[ 7]); + ds_list_add(_vertices, icoverts[ 7], icoverts[ 1], icoverts[10]); + ds_list_add(_vertices, icoverts[12], icoverts[ 5], icoverts[11]); + ds_list_add(_vertices, icoverts[11], icoverts[ 7], icoverts[12]); + ds_list_add(_vertices, icoverts[10], icoverts[ 3], icoverts[ 6]); + ds_list_add(_vertices, icoverts[ 6], icoverts[12], icoverts[10]); + ds_list_add(_vertices, icoverts[ 9], icoverts[ 2], icoverts[ 8]); + ds_list_add(_vertices, icoverts[ 8], icoverts[11], icoverts[ 9]); + ds_list_add(_vertices, icoverts[ 3], icoverts[ 4], icoverts[ 6]); + ds_list_add(_vertices, icoverts[ 9], icoverts[ 4], icoverts[ 2]); + ds_list_add(_vertices, icoverts[10], icoverts[ 1], icoverts[ 3]); + ds_list_add(_vertices, icoverts[ 2], icoverts[ 1], icoverts[ 8]); + ds_list_add(_vertices, icoverts[12], icoverts[ 7], icoverts[10]); + ds_list_add(_vertices, icoverts[ 8], icoverts[ 7], icoverts[11]); + ds_list_add(_vertices, icoverts[ 6], icoverts[ 5], icoverts[12]); + ds_list_add(_vertices, icoverts[11], icoverts[ 5], icoverts[ 9]); for( var w = 1; w <= level; w++ ) { #region subdivide ds_map_clear(_vhash); @@ -129,21 +129,21 @@ function __3dICOSphere(radius = 0.5, level = 2, smt = false) : __3dObject() cons if(smooth) { ds_list_add(_normals, _v0.normalize(), _v1.normalize(), _v2.normalize()); } else { - var _n = _v1.subtract(_v0).cross(_v2.subtract(_v0)); + var _n = _v2.subtract(_v0).cross(_v1.subtract(_v0)); ds_list_add(_normals, _n, _n, _n); } } #endregion - vertex = array_create(ds_list_size(_vertices)); - normals = array_create(ds_list_size(_normals)); + vertex = [ array_create(ds_list_size(_vertices)) ]; for( var i = 0, n = ds_list_size(_vertices); i < n; i++ ) - vertex[i] = V3(_vertices[| i]).setNormal(_normals[| i]); + vertex[0][i] = V3(_vertices[| i]).setNormal(_normals[| i]); ds_list_destroy(_vertices); ds_list_destroy(_normals); VB = build(); + generateNormal(); } initModel(); static onParameterUpdate = initModel; diff --git a/scripts/d3d_light/d3d_light.gml b/scripts/d3d_light/d3d_light.gml index 7f3e01e6d..98a5528c9 100644 --- a/scripts/d3d_light/d3d_light.gml +++ b/scripts/d3d_light/d3d_light.gml @@ -1,6 +1,7 @@ function __3dLight() : __3dObject() constructor { - UI_vertex = array_create(33); - for( var i = 0; i <= 32; i++ ) UI_vertex[i] = V3(0, lengthdir_x(0.5, i / 32 * 360), lengthdir_y(0.5, i / 32 * 360), c_yellow, 0.8); + UI_vertex = [ array_create(33) ]; + for( var i = 0; i <= 32; i++ ) + UI_vertex[0][i] = V3(0, lengthdir_x(0.5, i / 32 * 360), lengthdir_y(0.5, i / 32 * 360), c_yellow, 0.8); VB_UI = build(noone, UI_vertex); color = c_white; @@ -10,10 +11,11 @@ function __3dLight() : __3dObject() constructor { shadow_active = false; shadow_map = noone; shadow_map_size = 1024; - shadow_map_scale = 256; + shadow_map_scale = 4; shadow_map_camera = camera_create(); shadow_map_view = array_create(16, 0); shadow_map_proj = array_create(16, 0); + shadow_bias = 0.001; static getCenter = function() { return noone; } static getBBOX = function() { return noone; } diff --git a/scripts/d3d_light_directional/d3d_light_directional.gml b/scripts/d3d_light_directional/d3d_light_directional.gml index 85636a9a0..f75017343 100644 --- a/scripts/d3d_light_directional/d3d_light_directional.gml +++ b/scripts/d3d_light_directional/d3d_light_directional.gml @@ -1,5 +1,5 @@ function __3dLightDirectional() : __3dLight() constructor { - vertex = [ V3(1, 0, 0, c_yellow, 0.8), V3(3, 0, 0, c_yellow, 0.8) ]; + vertex = [[ V3(1, 0, 0, c_yellow, 0.8), V3(3, 0, 0, c_yellow, 0.8) ]]; VF = global.VF_POS_COL; render_type = pr_linelist; VB = build(); @@ -36,11 +36,11 @@ function __3dLightDirectional() : __3dLight() constructor { matrix_stack_push(rot); matrix_set(matrix_world, matrix_stack_top()); - vertex_submit(VB_UI, pr_linestrip, -1); + vertex_submit(VB_UI[0], pr_linestrip, -1); matrix_stack_push(sca); matrix_set(matrix_world, matrix_stack_top()); - vertex_submit(VB_UI, pr_linestrip, -1); + vertex_submit(VB_UI[0], pr_linestrip, -1); matrix_stack_clear(); matrix_set(matrix_world, matrix_build_identity()); @@ -50,7 +50,7 @@ function __3dLightDirectional() : __3dLight() constructor { shadow_map = surface_verify(shadow_map, shadow_map_size, shadow_map_size, surface_r32float); shadow_map_view = matrix_build_lookat(position.x, position.y, position.z, 0, 0, 0, 0, 0, -1); - shadow_map_proj = matrix_build_projection_ortho(shadow_map_size / shadow_map_scale, shadow_map_size / shadow_map_scale, .01, 100); + shadow_map_proj = matrix_build_projection_ortho(shadow_map_scale, shadow_map_scale, .01, 100); surface_set_target(shadow_map); draw_clear(c_black); diff --git a/scripts/d3d_light_point/d3d_light_point.gml b/scripts/d3d_light_point/d3d_light_point.gml index f2be28fac..1fd005521 100644 --- a/scripts/d3d_light_point/d3d_light_point.gml +++ b/scripts/d3d_light_point/d3d_light_point.gml @@ -5,7 +5,6 @@ function __3dLightPoint() : __3dLight() constructor { shadow_mapper = sh_d3d_shadow_depth; shadow_map_size = 512; - shadow_map_scale = 128; shadow_map_views = array_create(6); shadow_maps = array_create(6); @@ -39,16 +38,16 @@ function __3dLightPoint() : __3dLight() constructor { matrix_stack_push(rot); matrix_set(matrix_world, matrix_stack_top()); - vertex_submit(VB_UI, pr_linestrip, -1); + vertex_submit(VB_UI[0], pr_linestrip, -1); matrix_stack_push(sca); matrix_set(matrix_world, matrix_stack_top()); - vertex_submit(VB_UI, pr_linestrip, -1); + vertex_submit(VB_UI[0], pr_linestrip, -1); matrix_stack_pop(); matrix_stack_push(ran); matrix_set(matrix_world, matrix_stack_top()); - vertex_submit(VB_UI, pr_linestrip, -1); + vertex_submit(VB_UI[0], pr_linestrip, -1); matrix_stack_pop(); matrix_stack_clear(); diff --git a/scripts/d3d_material/d3d_material.gml b/scripts/d3d_material/d3d_material.gml new file mode 100644 index 000000000..5dcaddd7b --- /dev/null +++ b/scripts/d3d_material/d3d_material.gml @@ -0,0 +1,9 @@ +function __d3dMaterial(surface = noone, roughness = 0) constructor { + self.roughness = roughness; + self.surface = surface; + + static getTexture = function() { + if(!is_surface(surface)) return -1; + return surface_get_texture(surface); + } +} \ No newline at end of file diff --git a/scripts/d3d_material/d3d_material.yy b/scripts/d3d_material/d3d_material.yy new file mode 100644 index 000000000..21cac488a --- /dev/null +++ b/scripts/d3d_material/d3d_material.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "d3d_material", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "3d", + "path": "folders/functions/3d.yy", + }, +} \ No newline at end of file diff --git a/scripts/d3d_matrix4/d3d_matrix4.gml b/scripts/d3d_matrix4/d3d_matrix4.gml index 8a524780d..738be4428 100644 --- a/scripts/d3d_matrix4/d3d_matrix4.gml +++ b/scripts/d3d_matrix4/d3d_matrix4.gml @@ -73,13 +73,12 @@ function __mat4() constructor { var result = new __mat4(); // Perform matrix multiplication - for (var i = 0; i < 4; i++) { - for (var j = 0; j < 4; j++) { - var sum = 0; - for (var k = 0; k < 4; k++) - sum += raw[i * 4 + k] * matrix.raw[k * 4 + j]; - result.raw[i * 4 + j] = sum; - } + for (var i = 0; i < 4; i++) + for (var j = 0; j < 4; j++) { + var sum = 0; + for (var k = 0; k < 4; k++) + sum += raw[i * 4 + k] * matrix.raw[k * 4 + j]; + result.raw[i * 4 + j] = sum; } return result; diff --git a/scripts/d3d_object/d3d_object.gml b/scripts/d3d_object/d3d_object.gml index fe5a962f1..f8bbef5d9 100644 --- a/scripts/d3d_object/d3d_object.gml +++ b/scripts/d3d_object/d3d_object.gml @@ -14,8 +14,13 @@ function __3dObject() constructor { vertex = []; + normal_vertex = []; object_counts = 1; - VB = noone; + VB = noone; + + NVB = noone; + normal_draw_size = 0.2; + VF = global.VF_POS_COL; render_type = pr_trianglelist; @@ -26,9 +31,9 @@ function __3dObject() constructor { scale = new __vec3(1); size = new __vec3(1); - texture = -1; + materials = []; - static checkParameter = function(params = {}) { #region + static checkParameter = function(params = {}, forceUpdate = false) { #region var _keys = struct_get_names(params); var check = false; for( var i = 0, n = array_length(_keys); i < n; i++ ) { @@ -38,11 +43,33 @@ function __3dObject() constructor { self[$ key] = params[$ key]; } - if(check) onParameterUpdate(); + if(forceUpdate || check) onParameterUpdate(); } #endregion static onParameterUpdate = function() {} + static generateNormal = function() { #region + if(render_type != pr_trianglelist) return; + + NVB = array_create(object_counts); + var _s = normal_draw_size; + + for( var i = 0; i < object_counts; i++ ) { + NVB[i] = vertex_create_buffer(); + + vertex_begin(NVB[i], global.VF_POS_COL); + for( var j = 0, n = array_length(vertex[i]); j < n; j++ ) { + var _v = vertex[i][j]; + vertex_position_3d(NVB[i], _v.x, _v.y, _v.z); + vertex_color(NVB[i], c_red, 1); + + vertex_position_3d(NVB[i], _v.x + _v.normal.x * _s, _v.y + _v.normal.y * _s, _v.z + _v.normal.z * _s); + vertex_color(NVB[i], c_red, 1); + } + vertex_end(NVB[i]); + } + } #endregion + static buildVertex = function(_vertex, _normal, _uv) { #region var _buffer = vertex_create_buffer(); vertex_begin(_buffer, VF); @@ -59,7 +86,7 @@ function __3dObject() constructor { return _buffer; } #endregion - static build = function(_buffer = VB, _vertex = vertex) { #region + static build = function(_buffer = VB, _vertex = vertex, counts = object_counts) { #region if(is_array(_buffer)) { for( var i = 0, n = array_length(_buffer); i < n; i++ ) vertex_delete_buffer(_buffer[i]) @@ -67,10 +94,8 @@ function __3dObject() constructor { if(array_empty(_vertex)) return noone; - if(object_counts == 1) return buildVertex(_vertex); - - var _res = array_create(object_counts); - for( var i = 0; i < object_counts; i++ ) + var _res = array_create(counts); + for( var i = 0; i < counts; i++ ) _res[i] = buildVertex(_vertex[i]); return _res; @@ -86,7 +111,12 @@ function __3dObject() constructor { static submit = function(params = {}, shader = noone) { submitVertex(params, shader); } static submitUI = function(params = {}, shader = noone) { submitVertex(params, shader); } - static submitSel = function(params = {}) { submitVertex(params, sh_d3d_silhouette); } + + static submitSel = function(params = {}) { #region + var _p = variable_clone(params); + _p.show_normal = false; + submitVertex(_p, sh_d3d_silhouette); + } #endregion static submitVertex = function(params = {}, shader = noone) { #region if(shader != noone) @@ -135,16 +165,20 @@ function __3dObject() constructor { matrix_set(matrix_world, matrix_stack_top()); } - if(is_array(VB)) { - for( var i = 0, n = array_length(VB); i < n; i++ ) - vertex_submit(VB[i], render_type, array_safe_get(texture, i, -1)); - } else - vertex_submit(VB, render_type, texture); - - matrix_stack_clear(); - matrix_set(matrix_world, matrix_build_identity()); + for( var i = 0, n = array_length(VB); i < n; i++ ) + vertex_submit(VB[i], render_type, array_safe_get(texture, i, -1)); } + if(params.show_normal && NVB != noone) { + shader_set(sh_d3d_wireframe); + for( var i = 0, n = array_length(NVB); i < n; i++ ) + vertex_submit(NVB[i], pr_linelist, -1); + shader_reset(); + } + + matrix_stack_clear(); + matrix_set(matrix_world, matrix_build_identity()); + postSubmitVertex(params); shader_reset(); diff --git a/scripts/d3d_plane_mesh/d3d_plane_mesh.gml b/scripts/d3d_plane_mesh/d3d_plane_mesh.gml index fd406dce3..8c80e166a 100644 --- a/scripts/d3d_plane_mesh/d3d_plane_mesh.gml +++ b/scripts/d3d_plane_mesh/d3d_plane_mesh.gml @@ -2,26 +2,53 @@ function __3dPlane() : __3dObject() constructor { VF = global.VF_POS_NORM_TEX_COL; render_type = pr_trianglelist; - static initModel = function(size) { - size /= 2; - - vertex = [ - V3(-size, -size, 0), V3(size, -size, 0), V3(size, size, 0), - V3(-size, -size, 0), V3(size, size, 0), V3(-size, size, 0), - ]; + self.side = 0.5; + self.normal = 0; - normals = [ - [0, 0, 1], [0, 0, 1], [0, 0, 1], - [0, 0, 1], [0, 0, 1], [0, 0, 1], - ]; + static initModel = function() { + var _nor = [ 0, 0, 1 ]; + switch(normal) { + case 0 : + _nor = [ 1, 0, 0 ]; + vertex = [[ + V3(0, -side, -side).setNormal(_nor).setUV(0, 0), + V3(0, side, side).setNormal(_nor).setUV(1, 1), + V3(0, side, -side).setNormal(_nor).setUV(1, 0), + + V3(0, -side, -side).setNormal(_nor).setUV(0, 0), + V3(0, -side, side).setNormal(_nor).setUV(0, 1), + V3(0, side, side).setNormal(_nor).setUV(1, 1), + ]]; + break; + case 1 : + _nor = [ 0, 1, 0 ]; + vertex = [[ + V3(-side, 0, -side).setNormal(_nor).setUV(0, 0), + V3( side, 0, -side).setNormal(_nor).setUV(1, 0), + V3( side, 0, side).setNormal(_nor).setUV(1, 1), + + V3(-side, 0, -side).setNormal(_nor).setUV(0, 0), + V3( side, 0, side).setNormal(_nor).setUV(1, 1), + V3(-side, 0, side).setNormal(_nor).setUV(0, 1), + ]]; + break; + case 2 : + _nor = [ 0, 0, 1 ]; + vertex = [[ + V3(-side, -side, 0).setNormal(_nor).setUV(0, 0), + V3( side, side, 0).setNormal(_nor).setUV(1, 1), + V3( side, -side, 0).setNormal(_nor).setUV(1, 0), + + V3(-side, -side, 0).setNormal(_nor).setUV(0, 0), + V3(-side, side, 0).setNormal(_nor).setUV(0, 1), + V3( side, side, 0).setNormal(_nor).setUV(1, 1), + ]]; + break; + } - uv = [ - [0, 0], [1, 0], [1, 1], - [0, 0], [1, 1], [0, 1], - ]; - - array_foreach(vertex, function(val, ind) { val.normal.set(normals[ind]); val.uv.set(uv[ind]); }) - VB = build(); - } initModel(1); + generateNormal(); + } initModel(); + + onParameterUpdate = initModel; } \ No newline at end of file diff --git a/scripts/d3d_scene/d3d_scene.gml b/scripts/d3d_scene/d3d_scene.gml index 251a3613a..1185369d0 100644 --- a/scripts/d3d_scene/d3d_scene.gml +++ b/scripts/d3d_scene/d3d_scene.gml @@ -45,6 +45,8 @@ function __3dScene(camera) constructor { gammaCorrection = true; + show_normal = false; + static reset = function() { lightDir_count = 0; lightDir_direction = []; @@ -56,7 +58,7 @@ function __3dScene(camera) constructor { lightDir_shadowMap = []; lightDir_viewMat = []; lightDir_projMat = []; - lightDir_shadowBias = .001; + lightDir_shadowBias = []; lightPnt_count = 0; lightPnt_position = []; @@ -69,6 +71,7 @@ function __3dScene(camera) constructor { lightPnt_shadowMap = []; lightPnt_viewMat = []; lightPnt_projMat = []; + lightPnt_shadowBias = []; } reset(); static applyCamera = function() { camera.applyCamera(); } @@ -88,7 +91,7 @@ function __3dScene(camera) constructor { shader_set_surface($"light_dir_shadowmap_{i}", lightDir_shadowMap[i], true); shader_set_f("light_dir_view", lightDir_viewMat); shader_set_f("light_dir_proj", lightDir_projMat); - shader_set_f("shadowBias", lightDir_shadowBias); + shader_set_f("light_dir_shadow_bias", lightDir_shadowBias); } shader_set_i("light_pnt_count", lightPnt_count); @@ -102,9 +105,12 @@ function __3dScene(camera) constructor { shader_set_surface($"light_pnt_shadowmap_{i}", lightPnt_shadowMap[i], true, true); shader_set_f("light_pnt_view", lightPnt_viewMat); shader_set_f("light_pnt_proj", lightPnt_projMat); + shader_set_f("light_ont_shadow_bias", lightPnt_shadowBias); } - shader_set_i("gammaCorrection", gammaCorrection); + shader_set_i("gammaCorrection", gammaCorrection); + shader_set_f("planeNear", camera.view_near); + shader_set_f("planeFar", camera.view_far ); shader_reset(); } @@ -129,6 +135,7 @@ function __3dScene(camera) constructor { } array_append(lightDir_viewMat, light.shadow_map_view); array_append(lightDir_projMat, light.shadow_map_proj); + array_append(lightDir_shadowBias, light.shadow_bias); lightDir_count++; return self; @@ -156,6 +163,7 @@ function __3dScene(camera) constructor { } array_append(lightPnt_viewMat, light.shadow_map_view); array_append(lightPnt_projMat, light.shadow_map_proj); + array_append(lightPnt_shadowBias, light.shadow_bias); lightPnt_count++; return self; diff --git a/scripts/d3d_surface_extrude/d3d_surface_extrude.gml b/scripts/d3d_surface_extrude/d3d_surface_extrude.gml new file mode 100644 index 000000000..d1b313658 --- /dev/null +++ b/scripts/d3d_surface_extrude/d3d_surface_extrude.gml @@ -0,0 +1,301 @@ +function __3dSurfaceExtrude(surface = noone, height = noone, smooth = false) : __3dObject() constructor { + VF = global.VF_POS_NORM_TEX_COL; + render_type = pr_trianglelist; + + self.surface = surface; + self.height = height; + self.smooth = smooth; + + normal_draw_size = 0.05; + + static getHeight = function(h, gw, gh, i, j) { + var _i = round(i * gw); + var _j = round(j * gh); + + _i = clamp(_i, 0, array_length(h) - 1); + _j = clamp(_j, 0, array_length(h[_i]) - 1); + + return h[_i][_j]; + } + + static initModel = function() { + if(!is_surface(surface)) return; + + var _surface = surface; + var _height = height; + + var ww = surface_get_width(_surface); + var hh = surface_get_height(_surface); + + var tw = 1 / ww; + var th = 1 / hh; + var sw = -ww / 2 * tw; + var sh = hh / 2 * th; + var useH = is_surface(_height); + + #region ---- data prepare ---- + if(smooth) { + var ts = surface_create(ww, hh); + surface_set_shader(ts, sh_3d_extrude_filler); + shader_set_f("dimension", ww, hh); + draw_surface(_surface, 0, 0); + surface_reset_shader(); + _surface = ts; + + if(useH) { + var ds = surface_create(ww, hh); + surface_set_shader(ds, sh_3d_extrude_filler_depth); + shader_set_f("dimension", ww, hh); + draw_surface(_height, 0, 0); + surface_reset_shader(); + _height = ds; + } + } + + if(useH) { + var hgw = surface_get_width(_height); + var hgh = surface_get_height(_height); + var hgtW = hgw / ww; + var hgtH = hgh / hh; + + var height_buffer = buffer_create(hgw * hgh * 4, buffer_fixed, 2); + buffer_get_surface(height_buffer, _height, 0); + buffer_seek(height_buffer, buffer_seek_start, 0); + + var hei = array_create(hgw, hgh); + + for( var j = 0; j < hgh; j++ ) + for( var i = 0; i < hgw; i++ ) { + var cc = buffer_read(height_buffer, buffer_u32); + var _b = colorBrightness(cc & ~0b11111111); + hei[i][j] = _b; + } + + buffer_delete(height_buffer); + } + + var surface_buffer = buffer_create(ww * hh * 4, buffer_fixed, 2); + buffer_get_surface(surface_buffer, _surface, 0); + buffer_seek(surface_buffer, buffer_seek_start, 0); + + var v = ds_list_create(); + var ap = array_create(ww, hh); + + for( var j = 0; j < hh; j++ ) + for( var i = 0; i < ww; i++ ) { + var cc = buffer_read(surface_buffer, buffer_u32); + var _a = (cc & (0b11111111 << 24)) >> 24; + ap[i][j] = _a; + } + + buffer_delete(surface_buffer); + #endregion + + for( var i = 0; i < ww; i++ ) + for( var j = 0; j < hh; j++ ) { + if(!smooth && ap[i][j] == 0) continue; + + var j0 = sh - j * th; + var j1 = j0 - th; + var i0 = sw + i * tw; + var i1 = i0 + tw; + + var tx0 = tw * i, tx1 = tx0 + tw; + var ty0 = th * j, ty1 = ty0 + th; + + var dep = (useH? getHeight(hei, hgtW, hgtH, i, j) : 1) * 0.5; + + if(smooth) { #region + var d0, d1, d2, d3; + var d00, d10, d01, d11; + var a, a0, a1, a2, a3; + + // d00 | a0 | d10 + // a1 | a | a2 + // d01 | a3 | d11 + + if(useH) { + d00 = (i > 0 && j > 0)? getHeight(hei, hgtW, hgtH, i - 1, j - 1) * 0.5 : 0; + d10 = (i < ww - 1 && j > 0)? getHeight(hei, hgtW, hgtH, i + 1, j - 1) * 0.5 : 0; + d01 = (i > 0 && j < hh - 1)? getHeight(hei, hgtW, hgtH, i - 1, j + 1) * 0.5 : 0; + d11 = (i < ww - 1 && j < hh - 1)? getHeight(hei, hgtW, hgtH, i + 1, j + 1) * 0.5 : 0; + + d0 = (j > 0)? getHeight(hei, hgtW, hgtH, i, j - 1) * 0.5 : 0; + d1 = (i > 0)? getHeight(hei, hgtW, hgtH, i - 1, j) * 0.5 : 0; + d2 = (i < ww - 1)? getHeight(hei, hgtW, hgtH, i + 1, j) * 0.5 : 0; + d3 = (j < hh - 1)? getHeight(hei, hgtW, hgtH, i, j + 1) * 0.5 : 0; + } else { + d00 = (i > 0 && j > 0)? bool(ap[i - 1][j - 1]) * 0.5 : 0; + d10 = (i < ww - 1 && j > 0)? bool(ap[i + 1][j - 1]) * 0.5 : 0; + d01 = (i > 0 && j < hh - 1)? bool(ap[i - 1][j + 1]) * 0.5 : 0; + d11 = (i < ww - 1 && j < hh - 1)? bool(ap[i + 1][j + 1]) * 0.5 : 0; + + d0 = (j > 0)? bool(ap[i][j - 1]) * 0.5 : 0; + d1 = (i > 0)? bool(ap[i - 1][j]) * 0.5 : 0; + d2 = (i < ww - 1)? bool(ap[i + 1][j]) * 0.5 : 0; + d3 = (j < hh - 1)? bool(ap[i][j + 1]) * 0.5 : 0; + } + + a = ap[i][j]; + a0 = (j > 0)? ap[i][j - 1] : 0; + a1 = (i > 0)? ap[i - 1][j] : 0; + a2 = (i < ww - 1)? ap[i + 1][j] : 0; + a3 = (j < hh - 1)? ap[i][j + 1] : 0; + + if(a1 && a0) d00 = (d1 + d0) / 2; + if(a0 && a2) d10 = (d0 + d2) / 2; + if(a2 && a3) d11 = (d2 + d3) / 2; + if(a3 && a1) d01 = (d3 + d1) / 2; + + if(a) { + ds_list_add(v, V3(j0, i1, -d10).setNormal(0, 0, -1).setUV(tx1, ty0)); + ds_list_add(v, V3(j1, i1, -d11).setNormal(0, 0, -1).setUV(tx1, ty1)); + ds_list_add(v, V3(j0, i0, -d00).setNormal(0, 0, -1).setUV(tx0, ty0)); + + ds_list_add(v, V3(j1, i1, -d11).setNormal(0, 0, -1).setUV(tx1, ty1)); + ds_list_add(v, V3(j1, i0, -d01).setNormal(0, 0, -1).setUV(tx0, ty1)); + ds_list_add(v, V3(j0, i0, -d00).setNormal(0, 0, -1).setUV(tx0, ty0)); + + ds_list_add(v, V3(j0, i1, d10).setNormal(0, 0, 1).setUV(tx1, ty0)); + ds_list_add(v, V3(j0, i0, d00).setNormal(0, 0, 1).setUV(tx0, ty0)); + ds_list_add(v, V3(j1, i1, d11).setNormal(0, 0, 1).setUV(tx1, ty1)); + + ds_list_add(v, V3(j1, i1, d11).setNormal(0, 0, 1).setUV(tx1, ty1)); + ds_list_add(v, V3(j0, i0, d00).setNormal(0, 0, 1).setUV(tx0, ty0)); + ds_list_add(v, V3(j1, i0, d01).setNormal(0, 0, 1).setUV(tx0, ty1)); + } else if(!a0 && !a1 && a2 && a3) { + //var _tx0 = tw * (i + 1), _tx1 = _tx0 + tw; + //var _ty0 = th * (j + 0), _ty1 = _ty0 + th; + + d00 *= d0 * d1; + d10 *= d1 * d2; + d01 *= d1 * d3; + + ds_list_add(v, V3(j0, i1, -d10).setNormal(0, 0, -1).setUV(tx1, ty0)); + ds_list_add(v, V3(j1, i1, -d11).setNormal(0, 0, -1).setUV(tx1, ty1)); + ds_list_add(v, V3(j1, i0, -d01).setNormal(0, 0, -1).setUV(tx0, ty1)); + + ds_list_add(v, V3(j0, i1, d10).setNormal(0, 0, 1).setUV(tx1, ty0)); + ds_list_add(v, V3(j1, i1, d11).setNormal(0, 0, 1).setUV(tx1, ty1)); + ds_list_add(v, V3(j1, i0, d01).setNormal(0, 0, 1).setUV(tx0, ty1)); + } else if(!a0 && a1 && !a2 && a3) { + //var _tx0 = tw * (i - 1), _tx1 = _tx0 + tw; + //var _ty0 = th * (j + 0), _ty1 = _ty0 + th; + + d00 *= d0 * d1; + d10 *= d1 * d2; + d11 *= d2 * d3; + + ds_list_add(v, V3(j1, i1, -d11).setNormal(0, 0, -1).setUV(tx1, ty1)); + ds_list_add(v, V3(j1, i0, -d01).setNormal(0, 0, -1).setUV(tx0, ty1)); + ds_list_add(v, V3(j0, i0, -d00).setNormal(0, 0, -1).setUV(tx0, ty0)); + + ds_list_add(v, V3(j1, i1, d11).setNormal(0, 0, 1).setUV(tx1, ty1)); + ds_list_add(v, V3(j1, i0, d01).setNormal(0, 0, 1).setUV(tx0, ty1)); + ds_list_add(v, V3(j0, i0, d00).setNormal(0, 0, 1).setUV(tx0, ty0)); + } else if(a0 && a1 && !a2 && !a3) { + //var _tx0 = tw * (i - 1), _tx1 = _tx0 + tw; + //var _ty0 = th * (j + 0), _ty1 = _ty0 + th; + + d10 *= d1 * d2; + d01 *= d1 * d3; + d11 *= d2 * d3; + + ds_list_add(v, V3(j0, i0, -d00).setNormal(0, 0, -1).setUV(tx0, ty0)); + ds_list_add(v, V3(j0, i1, -d10).setNormal(0, 0, -1).setUV(tx1, ty0)); + ds_list_add(v, V3(j1, i0, -d01).setNormal(0, 0, -1).setUV(tx0, ty1)); + + ds_list_add(v, V3(j0, i0, d00).setNormal(0, 0, 1).setUV(tx0, ty0)); + ds_list_add(v, V3(j0, i1, d10).setNormal(0, 0, 1).setUV(tx1, ty0)); + ds_list_add(v, V3(j1, i0, d01).setNormal(0, 0, 1).setUV(tx0, ty1)); + } else if(a0 && !a1 && a2 && !a3) { + //var _tx0 = tw * (i + 1), _tx1 = _tx0 + tw; + //var _ty0 = th * (j + 0), _ty1 = _ty0 + th; + + d00 *= d0 * d1; + d01 *= d1 * d3; + d11 *= d2 * d3; + + ds_list_add(v, V3(j0, i1, -d10).setNormal(0, 0, -1).setUV(tx1, ty0)); + ds_list_add(v, V3(j1, i1, -d11).setNormal(0, 0, -1).setUV(tx1, ty1)); + ds_list_add(v, V3(j0, i0, -d00).setNormal(0, 0, -1).setUV(tx0, ty0)); + + ds_list_add(v, V3(j0, i1, d10).setNormal(0, 0, 1).setUV(tx1, ty0)); + ds_list_add(v, V3(j1, i1, d11).setNormal(0, 0, 1).setUV(tx1, ty1)); + ds_list_add(v, V3(j0, i0, d00).setNormal(0, 0, 1).setUV(tx0, ty0)); + } + #endregion + } else { #region + ds_list_add(v, V3(i1, j0, -dep).setNormal(0, 0, -1).setUV(tx1, ty0)); + ds_list_add(v, V3(i0, j0, -dep).setNormal(0, 0, -1).setUV(tx0, ty0)); + ds_list_add(v, V3(i1, j1, -dep).setNormal(0, 0, -1).setUV(tx1, ty1)); + + ds_list_add(v, V3(i1, j1, -dep).setNormal(0, 0, -1).setUV(tx1, ty1)); + ds_list_add(v, V3(i0, j0, -dep).setNormal(0, 0, -1).setUV(tx0, ty0)); + ds_list_add(v, V3(i0, j1, -dep).setNormal(0, 0, -1).setUV(tx0, ty1)); + + ds_list_add(v, V3(i1, j0, dep).setNormal(0, 0, 1).setUV(tx1, ty0)); + ds_list_add(v, V3(i1, j1, dep).setNormal(0, 0, 1).setUV(tx1, ty1)); + ds_list_add(v, V3(i0, j0, dep).setNormal(0, 0, 1).setUV(tx0, ty0)); + + ds_list_add(v, V3(i1, j1, dep).setNormal(0, 0, 1).setUV(tx1, ty1)); + ds_list_add(v, V3(i0, j1, dep).setNormal(0, 0, 1).setUV(tx0, ty1)); + ds_list_add(v, V3(i0, j0, dep).setNormal(0, 0, 1).setUV(tx0, ty0)); + + if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i, j - 1)) || (j == 0 || ap[i][j - 1] == 0)) { //y side + ds_list_add(v, V3(i0, j0, dep).setNormal(0, 1, 0).setUV(tx1, ty0)); + ds_list_add(v, V3(i0, j0, -dep).setNormal(0, 1, 0).setUV(tx0, ty0)); + ds_list_add(v, V3(i1, j0, dep).setNormal(0, 1, 0).setUV(tx1, ty1)); + + ds_list_add(v, V3(i0, j0, -dep).setNormal(0, 1, 0).setUV(tx1, ty1)); + ds_list_add(v, V3(i1, j0, -dep).setNormal(0, 1, 0).setUV(tx0, ty0)); + ds_list_add(v, V3(i1, j0, dep).setNormal(0, 1, 0).setUV(tx0, ty1)); + } + + if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i, j + 1)) || (j == hh - 1 || ap[i][j + 1] == 0)) { //y side + ds_list_add(v, V3(i0, j1, dep).setNormal(0, -1, 0).setUV(tx1, ty0)); + ds_list_add(v, V3(i1, j1, dep).setNormal(0, -1, 0).setUV(tx1, ty1)); + ds_list_add(v, V3(i0, j1, -dep).setNormal(0, -1, 0).setUV(tx0, ty0)); + + ds_list_add(v, V3(i0, j1, -dep).setNormal(0, -1, 0).setUV(tx1, ty1)); + ds_list_add(v, V3(i1, j1, dep).setNormal(0, -1, 0).setUV(tx0, ty1)); + ds_list_add(v, V3(i1, j1, -dep).setNormal(0, -1, 0).setUV(tx0, ty0)); + } + + if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i - 1, j)) || (i == 0 || ap[i - 1][j] == 0)) { //x side + ds_list_add(v, V3(i0, j0, dep).setNormal(-1, 0, 0).setUV(tx1, ty0)); + ds_list_add(v, V3(i0, j1, dep).setNormal(-1, 0, 0).setUV(tx1, ty1)); + ds_list_add(v, V3(i0, j0, -dep).setNormal(-1, 0, 0).setUV(tx0, ty0)); + + ds_list_add(v, V3(i0, j0, -dep).setNormal(-1, 0, 0).setUV(tx1, ty1)); + ds_list_add(v, V3(i0, j1, dep).setNormal(-1, 0, 0).setUV(tx0, ty1)); + ds_list_add(v, V3(i0, j1, -dep).setNormal(-1, 0, 0).setUV(tx0, ty0)); + } + + if((useH && dep * 2 > getHeight(hei, hgtW, hgtH, i + 1, j)) || (i == ww - 1 || ap[i + 1][j] == 0)) { //x side + ds_list_add(v, V3(i1, j0, dep).setNormal(1, 0, 0).setUV(tx1, ty0)); + ds_list_add(v, V3(i1, j0, -dep).setNormal(1, 0, 0).setUV(tx0, ty0)); + ds_list_add(v, V3(i1, j1, dep).setNormal(1, 0, 0).setUV(tx1, ty1)); + + ds_list_add(v, V3(i1, j0, -dep).setNormal(1, 0, 0).setUV(tx1, ty1)); + ds_list_add(v, V3(i1, j1, -dep).setNormal(1, 0, 0).setUV(tx0, ty0)); + ds_list_add(v, V3(i1, j1, dep).setNormal(1, 0, 0).setUV(tx0, ty1)); + } + #endregion + } + } + + if(smooth) { + surface_free(_surface); + if(useH) surface_free(_height); + } + + vertex = [ ds_list_to_array(v) ]; + ds_list_destroy(v); + + VB = build(); + generateNormal(); + } initModel(); + + static onParameterUpdate = initModel; +} \ No newline at end of file diff --git a/scripts/d3d_surface_extrude/d3d_surface_extrude.yy b/scripts/d3d_surface_extrude/d3d_surface_extrude.yy new file mode 100644 index 000000000..8fa0559de --- /dev/null +++ b/scripts/d3d_surface_extrude/d3d_surface_extrude.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "d3d_surface_extrude", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "mesh", + "path": "folders/functions/3d/mesh.yy", + }, +} \ No newline at end of file diff --git a/scripts/d3d_uvsphere/d3d_uvsphere.gml b/scripts/d3d_uvsphere/d3d_uvsphere.gml index 43c5e716e..7bba9ca36 100644 --- a/scripts/d3d_uvsphere/d3d_uvsphere.gml +++ b/scripts/d3d_uvsphere/d3d_uvsphere.gml @@ -8,7 +8,7 @@ function __3dUVSphere(radius = 0.5, hori = 16, vert = 8, smt = false) : __3dObje self.smooth = smt; static initModel = function() { // swap H, V because fuck me - vertex = array_create(vert * hori * 2 * 3); + vertex = [ array_create(vert * hori * 2 * 3) ]; var amo = 0; for (var i = 0; i < vert; i++) @@ -53,45 +53,46 @@ function __3dUVSphere(radius = 0.5, hori = 16, vert = 8, smt = false) : __3dObje var ind = (i * hori + j) * 6; - vertex[ind + 0] = V3(hx0, hy0, hz0); - vertex[ind + 1] = V3(hx1, hy1, hz1); - vertex[ind + 2] = V3(hx2, hy2, hz2); + vertex[0][ind + 0] = V3(hx0, hy0, hz0); + vertex[0][ind + 1] = V3(hx1, hy1, hz1); + vertex[0][ind + 2] = V3(hx2, hy2, hz2); - vertex[ind + 3] = V3(hx1, hy1, hz1); - vertex[ind + 4] = V3(hx2, hy2, hz2); - vertex[ind + 5] = V3(hx3, hy3, hz3); + vertex[0][ind + 3] = V3(hx1, hy1, hz1); + vertex[0][ind + 4] = V3(hx3, hy3, hz3); + vertex[0][ind + 5] = V3(hx2, hy2, hz2); if(smooth) { - vertex[ind + 0].setNormal(hx0, hy0, hz0); - vertex[ind + 1].setNormal(hx1, hy1, hz1); - vertex[ind + 2].setNormal(hx2, hy2, hz2); - - vertex[ind + 3].setNormal(hx1, hy1, hz1); - vertex[ind + 4].setNormal(hx2, hy2, hz2); - vertex[ind + 5].setNormal(hx3, hy3, hz3); + vertex[0][ind + 0].setNormal(hx0, hy0, hz0); + vertex[0][ind + 1].setNormal(hx1, hy1, hz1); + vertex[0][ind + 2].setNormal(hx2, hy2, hz2); + + vertex[0][ind + 3].setNormal(hx1, hy1, hz1); + vertex[0][ind + 4].setNormal(hx3, hy3, hz3); + vertex[0][ind + 5].setNormal(hx2, hy2, hz2); } else { var nor = d3_cross_product([hx2 - hx0, hy2 - hy0, hz2 - hz0], [hx1 - hx0, hy1 - hy0, hz1 - hz0]); nor = d3_normalize(nor); - vertex[ind + 0].setNormal(nor); - vertex[ind + 1].setNormal(nor); - vertex[ind + 2].setNormal(nor); - - vertex[ind + 3].setNormal(nor); - vertex[ind + 4].setNormal(nor); - vertex[ind + 5].setNormal(nor); + vertex[0][ind + 0].setNormal(nor); + vertex[0][ind + 1].setNormal(nor); + vertex[0][ind + 2].setNormal(nor); + + vertex[0][ind + 3].setNormal(nor); + vertex[0][ind + 4].setNormal(nor); + vertex[0][ind + 5].setNormal(nor); } - vertex[ind + 0].setUV(u0, v0); - vertex[ind + 1].setUV(u1, v1); - vertex[ind + 2].setUV(u2, v2); - - vertex[ind + 3].setUV(u1, v1); - vertex[ind + 4].setUV(u2, v2); - vertex[ind + 5].setUV(u3, v3); + vertex[0][ind + 0].setUV(u0, v0); + vertex[0][ind + 1].setUV(u1, v1); + vertex[0][ind + 2].setUV(u2, v2); + + vertex[0][ind + 3].setUV(u1, v1); + vertex[0][ind + 4].setUV(u3, v3); + vertex[0][ind + 5].setUV(u2, v2); } VB = build(); + generateNormal(); } initModel(); static onParameterUpdate = initModel; diff --git a/scripts/d3d_vertex/d3d_vertex.gml b/scripts/d3d_vertex/d3d_vertex.gml index 37a09e2a1..da1b487bc 100644 --- a/scripts/d3d_vertex/d3d_vertex.gml +++ b/scripts/d3d_vertex/d3d_vertex.gml @@ -10,7 +10,7 @@ function __vertex(_x = 0, _y = _x, _z = _x, color = c_white, alpha = 1) : __vec3 self.alpha = alpha; static setNormal = function(_nx = 0, _ny = _nx, _nz = _nx) { - normal.set(_nx, _ny, _nx)._normalize(); + normal.set(_nx, _ny, _nz)._normalize(); return self; } @@ -19,7 +19,7 @@ function __vertex(_x = 0, _y = _x, _z = _x, color = c_white, alpha = 1) : __vec3 return self; } - static toString = function() { return $"[{x}, {y}, {z}, {color}, {alpha}]"; } + static toString = function() { return $"[ pos: ({x}, {y}, {z}), nor: {normal}, uv: {uv}, {color}, {alpha} ]"; } static clone = function() { gml_pragma("forceinline"); diff --git a/scripts/node_3d_camera/node_3d_camera.gml b/scripts/node_3d_camera/node_3d_camera.gml index 7cd00063e..1471cd57e 100644 --- a/scripts/node_3d_camera/node_3d_camera.gml +++ b/scripts/node_3d_camera/node_3d_camera.gml @@ -1,5 +1,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) constructor { name = "3D Camera"; + batch_output = true; + object = new __3dCamera_object(); camera = new __3dCamera(); lookat = new __3dGizmoSphere(0.5, c_ltgray, 1); @@ -11,10 +13,10 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) scene = new __3dScene(camera); scene.name = "Camera"; - inputs[| in_d3d + 0] = nodeValue("FOV", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 60) + inputs[| in_d3d + 0] = nodeValue("FOV", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 60 ) .setDisplay(VALUE_DISPLAY.slider, [ 10, 90, 1 ]); - inputs[| in_d3d + 1] = nodeValue("Clipping Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0.01, 100 ]) + inputs[| in_d3d + 1] = nodeValue("Clipping Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 0.01, 10 ] ) .setDisplay(VALUE_DISPLAY.vector); inputs[| in_d3d + 2] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF ) @@ -30,36 +32,44 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) inputs[| in_d3d + 6] = nodeValue("Show Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); - inputs[| in_d3d + 7] = nodeValue("Backface Culling", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + inputs[| in_d3d + 7] = nodeValue("Backface Culling", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2 ) .setDisplay(VALUE_DISPLAY.enum_button, [ "None", "CW", "CCW" ]); - inputs[| in_d3d + 8] = nodeValue("Orthographic Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1) + inputs[| in_d3d + 8] = nodeValue("Orthographic Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 ) .setDisplay(VALUE_DISPLAY.slider, [ 0.01, 4, 0.01 ]); - inputs[| in_d3d + 9] = nodeValue("Postioning Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) - .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Position + Rotation", "Position + Lookat", "Lookat + Rotation" ]); + inputs[| in_d3d + 9] = nodeValue("Postioning Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 ) + .setDisplay(VALUE_DISPLAY.enum_scroll, [ "Position + Rotation", "Position + Lookat", "Lookat + Rotation" ] ); - inputs[| in_d3d + 10] = nodeValue("Lookat Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ]) + inputs[| in_d3d + 10] = nodeValue("Lookat Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ] ) .setDisplay(VALUE_DISPLAY.vector); - inputs[| in_d3d + 11] = nodeValue("Roll", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0) + inputs[| in_d3d + 11] = nodeValue("Roll", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ) .setDisplay(VALUE_DISPLAY.rotation); - inputs[| in_d3d + 12] = nodeValue("Horizontal Angle", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0) + inputs[| in_d3d + 12] = nodeValue("Horizontal Angle", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 ) .setDisplay(VALUE_DISPLAY.rotation); - inputs[| in_d3d + 13] = nodeValue("Vertical Angle", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 45) + inputs[| in_d3d + 13] = nodeValue("Vertical Angle", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 45 ) .setDisplay(VALUE_DISPLAY.slider, [0, 90, 1]); - inputs[| in_d3d + 14] = nodeValue("Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 4); + inputs[| in_d3d + 14] = nodeValue("Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 4 ); - outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); + inputs[| in_d3d + 15] = nodeValue("Gamma Adjust", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); + + outputs[| 0] = nodeValue("Rendered", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone ); + + outputs[| 1] = nodeValue("Normal", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone ) + .setVisible(false); + + outputs[| 2] = nodeValue("Depth", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone ) + .setVisible(false); input_display_list = [ in_d3d + 4, ["Output", false], in_d3d + 2, ["Transform", false], in_d3d + 9, 0, 1, in_d3d + 10, in_d3d + 11, in_d3d + 12, in_d3d + 13, in_d3d + 14, ["Camera", false], in_d3d + 3, in_d3d + 0, in_d3d + 1, in_d3d + 8, - ["Render", false], in_d3d + 5, in_d3d + 6, in_d3d + 7, + ["Render", false], in_d3d + 5, in_d3d + 6, in_d3d + 7, in_d3d + 15, ]; tool_lookat = new NodeTool( "Move Target", THEME.tools_3d_transform_object ); @@ -153,6 +163,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) var _hAng = _data[in_d3d + 12]; var _vAng = _data[in_d3d + 13]; var _dist = _data[in_d3d + 14]; + var _gamm = _data[in_d3d + 15]; var _qi1 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(0, 1, 0), 90); var _qi2 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(1, 0, 0), -90); @@ -182,11 +193,11 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) camera.focus.set(_look); camera.setFocusAngle(_hAng, _vAng, _dist); camera.setCameraLookRotate(); - camera.up = camera.getUp(); + camera.up = camera.getUp()._multiply(-1); var _for = camera.focus.subtract(camera.position); if(!_for.isZero()) - camera.rotation = new BBMOD_Quaternion().FromLookRotation(_for, camera.up).Mul(_qi1).Mul(_qi3); + camera.rotation = new BBMOD_Quaternion().FromLookRotation(_for, camera.up.multiply(-1)).Mul(_qi1).Mul(_qi3); lookat.position.set(_look); lookLine = new __3dGizmoLineDashed(camera.position, camera.focus, 0.25, c_gray, 1); @@ -210,12 +221,16 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) else if(_proj == 1) camera.setViewSize(1 / _orts, _dim[0] / _dim[1] / _orts); scene.lightAmbient = _ambt; + _scne.gammaCorrection = _gamm; - _output = surface_verify(_output, _dim[0], _dim[1]); + var _render = surface_create(_dim[0], _dim[1]); + var _normal = surface_create(_dim[0], _dim[1]); + var _depth = surface_create(_dim[0], _dim[1]); - camera.setMatrix(); + surface_set_target_ext(0, _render); + surface_set_target_ext(1, _normal); + surface_set_target_ext(2, _depth ); - surface_set_target(_output); if(_dbg) draw_clear(_ambt); else DRAW_CLEAR @@ -223,6 +238,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) gpu_set_ztestenable(true); gpu_set_cullmode(_back); + camera.setMatrix(); camera.applyCamera(); scene.reset(); @@ -235,17 +251,15 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group) scene.resetCamera(); - return _output; + return [ _render, _normal, _depth ]; } #endregion - static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { - - } + static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {} static getPreviewObject = function() { #region var _posm = inputs[| in_d3d + 9].getValue(); - var _scene = array_safe_get(all_inputs, in_d3d + 4, []); + var _scene = array_safe_get(all_inputs, in_d3d + 4, noone); if(is_array(_scene)) _scene = array_safe_get(_scene, preview_index, noone); diff --git a/scripts/node_3d_light_directional/node_3d_light_directional.gml b/scripts/node_3d_light_directional/node_3d_light_directional.gml index fec35c160..1af804ba1 100644 --- a/scripts/node_3d_light_directional/node_3d_light_directional.gml +++ b/scripts/node_3d_light_directional/node_3d_light_directional.gml @@ -7,12 +7,14 @@ function Node_3D_Light_Directional(_x, _y, _group = noone) : Node_3D_Light(_x, _ inputs[| in_light + 1] = nodeValue("Shadow Map Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1024); - inputs[| in_light + 2] = nodeValue("Shadow Map Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 256); + inputs[| in_light + 2] = nodeValue("Shadow Map Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4); + + inputs[| in_light + 3] = nodeValue("Shadow Bias", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, .001); input_display_list = [ ["Transform", false], 0, __d3d_input_list_light, - ["Shadow", false], in_light + 0, in_light + 1, in_light + 2, + ["Shadow", false], in_light + 0, in_light + 1, in_light + 2, in_light + 3, ] tools = [ tool_pos ]; @@ -26,12 +28,14 @@ function Node_3D_Light_Directional(_x, _y, _group = noone) : Node_3D_Light(_x, _ var _shadow_active = _data[in_light + 0]; var _shadow_map_size = _data[in_light + 1]; var _shadow_map_scal = _data[in_light + 2]; + var _shadow_bias = _data[in_light + 3]; var object = getObject(_array_index); setTransform(object, _data); setLight(object, _data); object.setShadow(_shadow_active, _shadow_map_size, _shadow_map_scal); + object.shadow_bias = _shadow_bias; var _rot = new __rot3().lookAt(object.position, new __vec3()); object.rotation.FromEuler(_rot.x, _rot.y, _rot.z); diff --git a/scripts/node_3d_light_point/node_3d_light_point.gml b/scripts/node_3d_light_point/node_3d_light_point.gml index e75ecf0ea..fa00c6d97 100644 --- a/scripts/node_3d_light_point/node_3d_light_point.gml +++ b/scripts/node_3d_light_point/node_3d_light_point.gml @@ -9,6 +9,8 @@ function Node_3D_Light_Point(_x, _y, _group = noone) : Node_3D_Light(_x, _y, _gr inputs[| in_light + 2] = nodeValue("Shadow Map Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1024); + inputs[| in_light + 3] = nodeValue("Shadow Bias", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, .001); + input_display_list = [ ["Transform", false], 0, __d3d_input_list_light, in_light, @@ -26,6 +28,7 @@ function Node_3D_Light_Point(_x, _y, _group = noone) : Node_3D_Light(_x, _y, _gr var _radius = _data[in_light + 0]; var _shadow_active = _data[in_light + 1]; var _shadow_map_size = _data[in_light + 2]; + var _shadow_bias = _data[in_light + 3]; var object = getObject(_array_index); @@ -33,6 +36,7 @@ function Node_3D_Light_Point(_x, _y, _group = noone) : Node_3D_Light(_x, _y, _gr setLight(object, _data); object.setShadow(_shadow_active, _shadow_map_size); object.radius = _radius; + object.shadow_bias = _shadow_bias; return object; } diff --git a/scripts/node_3d_mesh_cube/node_3d_mesh_cube.gml b/scripts/node_3d_mesh_cube/node_3d_mesh_cube.gml index e8935b646..81592271c 100644 --- a/scripts/node_3d_mesh_cube/node_3d_mesh_cube.gml +++ b/scripts/node_3d_mesh_cube/node_3d_mesh_cube.gml @@ -24,11 +24,6 @@ function Node_3D_Mesh_Cube(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group in_mesh + 4, in_mesh + 5, in_mesh + 6, ] - static newObject = function(_side) { - if(_side) return new __3dCubeFaces(); - return new __3dCube(); - } - static step = function() { #region var _tex_side = inputs[| in_mesh + 0].getValue(); @@ -58,7 +53,7 @@ function Node_3D_Mesh_Cube(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group surface_texture(_tex_5), surface_texture(_tex_6) ]; } else { object = getObject(_array_index, __3dCube); - object.texture = surface_texture(_tex_1); + object.texture = [ surface_texture(_tex_1) ]; } setTransform(object, _data); diff --git a/scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.gml b/scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.gml new file mode 100644 index 000000000..d846051d2 --- /dev/null +++ b/scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.gml @@ -0,0 +1,36 @@ +function Node_3D_Mesh_Extrude(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) constructor { + name = "Surface Extrude"; + + object_class = __3dSurfaceExtrude; + + inputs[| in_mesh + 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); + + inputs[| in_mesh + 1] = nodeValue("Height map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); + + inputs[| in_mesh + 2] = nodeValue("Smooth", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false) + + inputs[| in_mesh + 3] = nodeValue("Always update", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); + + input_display_list = [ + __d3d_input_list_mesh, + __d3d_input_list_transform, + ["Extrude", false], in_mesh + 0, in_mesh + 1, in_mesh + 3, + ] + + static processData = function(_output, _data, _output_index, _array_index = 0) { #region + var _surf = _data[in_mesh + 0]; + var _hght = _data[in_mesh + 1]; + var _smt = _data[in_mesh + 2]; + var _updt = _data[in_mesh + 3]; + + var object = getObject(_array_index); + object.checkParameter({surface: _surf, height: _hght, smooth: _smt}, _updt); + object.texture = [ surface_texture(_surf) ]; + + setTransform(object, _data); + + return object; + } #endregion + + static getPreviewValues = function() { return array_safe_get(all_inputs, in_mesh + 0, noone); } +} \ No newline at end of file diff --git a/scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.yy b/scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.yy new file mode 100644 index 000000000..a10e7ab1b --- /dev/null +++ b/scripts/node_3d_mesh_extrude/node_3d_mesh_extrude.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "node_3d_mesh_extrude", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "d3d mesh", + "path": "folders/nodes/data/3D/d3d mesh.yy", + }, +} \ No newline at end of file diff --git a/scripts/node_3d_mesh_extrude/node_counter.yy b/scripts/node_3d_mesh_extrude/node_counter.yy new file mode 100644 index 000000000..10832a0b0 --- /dev/null +++ b/scripts/node_3d_mesh_extrude/node_counter.yy @@ -0,0 +1,12 @@ +{ + "isDnD": false, + "isCompatibility": false, + "parent": { + "name": "variable", + "path": "folders/nodes/data/variable.yy", + }, + "resourceVersion": "1.0", + "name": "node_counter", + "tags": [], + "resourceType": "GMScript", +} \ No newline at end of file diff --git a/scripts/node_3d_mesh_icosphere/node_3d_mesh_icosphere.gml b/scripts/node_3d_mesh_icosphere/node_3d_mesh_icosphere.gml index b71b767a5..fe1c019ee 100644 --- a/scripts/node_3d_mesh_icosphere/node_3d_mesh_icosphere.gml +++ b/scripts/node_3d_mesh_icosphere/node_3d_mesh_icosphere.gml @@ -22,7 +22,7 @@ function Node_3D_Mesh_Sphere_Ico(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, var object = getObject(_array_index); object.checkParameter({level: _sub, smooth: _smt}); - object.texture = surface_texture(_tex); + object.texture = [ surface_texture(_tex) ]; setTransform(object, _data); 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 0ec967ef8..2a1baa2b4 100644 --- a/scripts/node_3d_mesh_obj/node_3d_mesh_obj.gml +++ b/scripts/node_3d_mesh_obj/node_3d_mesh_obj.gml @@ -48,6 +48,14 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) materialIndex = []; use_normal = false; + insp1UpdateTooltip = __txt("Refresh"); + insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ]; + + static onInspector1Update = function() { + var _path = inputs[| in_mesh + 0].getValue(); + updateObj(_path); + } + function setPath(path) { inputs[| in_mesh + 0].setValue(path); updateObj(path); @@ -95,6 +103,8 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) object.vertex = _v.vertex; object.object_counts = _v.object_counts; + object.generateNormal(); + object.size = _v.model_size; materialNames = _v.materials; materialIndex = _v.material_index; @@ -140,6 +150,7 @@ function Node_3D_Mesh_Obj(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) _object.VF = global.VF_POS_NORM_TEX_COL; _object.VB = object.VB; + _object.NVB = object.NVB; _object.vertex = object.vertex; _object.object_counts = object.object_counts; _object.texture = textures; diff --git a/scripts/node_3d_mesh_plane/node_3d_mesh_plane.gml b/scripts/node_3d_mesh_plane/node_3d_mesh_plane.gml index a251e9dd3..14925d9fa 100644 --- a/scripts/node_3d_mesh_plane/node_3d_mesh_plane.gml +++ b/scripts/node_3d_mesh_plane/node_3d_mesh_plane.gml @@ -1,23 +1,26 @@ function Node_3D_Mesh_Plane(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) constructor { name = "3D Plane"; - object_class = __3dPlane(); + object_class = __3dPlane; inputs[| in_mesh + 0] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ); + inputs[| in_mesh + 1] = nodeValue("Normal", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2 ) + .setDisplay(VALUE_DISPLAY.enum_button, [ "X", "Y", "Z" ]); + input_display_list = [ - __d3d_input_list_mesh, + __d3d_input_list_mesh, in_mesh + 1, __d3d_input_list_transform, ["Texture", false], in_mesh + 0, ] static processData = function(_output, _data, _output_index, _array_index = 0) { #region var _tex = _data[in_mesh + 0]; + var _axs = _data[in_mesh + 1]; - var object; - - object = getObject(_array_index, __3dCube); - object.texture = surface_texture(_tex); + var object = getObject(_array_index); + object.checkParameter({normal: _axs}); + object.texture = [ surface_texture(_tex) ]; setTransform(object, _data); diff --git a/scripts/node_3d_mesh_uvsphere/node_3d_mesh_uvsphere.gml b/scripts/node_3d_mesh_uvsphere/node_3d_mesh_uvsphere.gml index e3ead837c..6f59f4f7c 100644 --- a/scripts/node_3d_mesh_uvsphere/node_3d_mesh_uvsphere.gml +++ b/scripts/node_3d_mesh_uvsphere/node_3d_mesh_uvsphere.gml @@ -3,11 +3,11 @@ function Node_3D_Mesh_Sphere_UV(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _ object_class = __3dUVSphere; - inputs[| in_mesh + 0] = nodeValue("Horizontal Slices", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 16 ); + inputs[| in_mesh + 0] = nodeValue("Horizontal Slices", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 8 ); - inputs[| in_mesh + 1] = nodeValue("Vertical Slices", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 8 ); + inputs[| in_mesh + 1] = nodeValue("Vertical Slices", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 16 ); - inputs[| in_mesh + 2] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ); + inputs[| in_mesh + 2] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 3] = nodeValue("Smooth Normal", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); @@ -25,7 +25,7 @@ function Node_3D_Mesh_Sphere_UV(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _ var object = getObject(_array_index); object.checkParameter({hori: _sideH, vert: _sideV, smooth: _smt}); - object.texture = surface_texture(_tex); + object.texture = [ surface_texture(_tex) ]; setTransform(object, _data); diff --git a/scripts/node_processor/node_processor.gml b/scripts/node_processor/node_processor.gml index 0b6fb3dc4..e2f4b1d48 100644 --- a/scripts/node_processor/node_processor.gml +++ b/scripts/node_processor/node_processor.gml @@ -18,6 +18,8 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct process_length = []; dimension_index = 0; + batch_output = false; //Run processData once with all outputs as array. + icon = THEME.node_processor; array_push(attributeEditors, "Array processor"); @@ -64,20 +66,19 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct return [1, 1]; } #endregion - static preProcess = function(outIndex) { #region - var _out = outputs[| outIndex].getValue(); - all_inputs = array_create(ds_list_size(inputs)); + static processDataArray = function(outIndex) { #region + var _output = outputs[| outIndex]; + var _out = _output.getValue(); + all_inputs = array_create(ds_list_size(inputs)); - if(process_amount == 0) { #region render single data - if(outputs[| outIndex].type == VALUE_TYPE.d3object) //passing 3D vertex call + if(process_amount == 1) { #region render single data + if(_output.type == VALUE_TYPE.d3object) //passing 3D vertex call return _out; - if(is_array(_out) && outputs[| outIndex].type == VALUE_TYPE.surface) { //free surface if needed - for(var i = 1; i < array_length(_out); i++) - if(is_surface(_out[i])) surface_free(_out[i]); - } + if(_output.type == VALUE_TYPE.surface) //free surface if needed + surface_array_free(_out); - if(outputs[| outIndex].type == VALUE_TYPE.surface && dimension_index > -1) { //resize surface + if(_output.type == VALUE_TYPE.surface && dimension_index > -1) { //resize surface var surf = inputs_data[dimension_index]; var _sw = 1, _sh = 1; if(inputs[| dimension_index].type == VALUE_TYPE.surface) { @@ -108,52 +109,19 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct return data; } #endregion - if(outputs[| outIndex].type == VALUE_TYPE.d3object) { #region passing 3D vertex call - if(is_array(_out)) _out = _out[0]; - return array_create(process_amount, _out); - } #endregion - #region ++++ array preparation ++++ if(!is_array(_out)) _out = array_create(process_amount); else if(array_length(_out) != process_amount) array_resize(_out, process_amount); - - var _data = array_create(ds_list_size(inputs)); - - for(var i = 0; i < ds_list_size(inputs); i++) - all_inputs[i] = array_create(process_amount); #endregion + var _data = array_create(ds_list_size(inputs)); for(var l = 0; l < process_amount; l++) { - for(var i = 0; i < ds_list_size(inputs); i++) { #region input preparation - var _in = inputs_data[i]; - - if(!inputs_is_array[i]) { - _data[i] = _in; - all_inputs[i][l] = _data[i]; - continue; - } - - if(array_length(_in) == 0) { - _data[i] = 0; - all_inputs[i][l] = _data[i]; - continue; - } - - var _index = 0; - switch(attributes.array_process) { - case ARRAY_PROCESS.loop : _index = safe_mod(l, array_length(_in)); break; - case ARRAY_PROCESS.hold : _index = min(l, array_length(_in) - 1); break; - case ARRAY_PROCESS.expand : _index = floor(l / process_length[i][1]) % process_length[i][0]; break; - case ARRAY_PROCESS.expand_inv : _index = floor(l / process_length[ds_list_size(inputs) - 1 - i][1]) % process_length[i][0]; break; - } - - _data[i] = inputs[| i].arrayBalance(_in[_index]); - all_inputs[i][l] = _data[i]; - } #endregion + for(var i = 0; i < ds_list_size(inputs); i++) + _data[i] = all_inputs[i][l]; - if(outputs[| outIndex].type == VALUE_TYPE.surface && dimension_index > -1) { #region output surface verification + if(_output.type == VALUE_TYPE.surface && dimension_index > -1) { #region output surface verification var surf = _data[dimension_index]; var _sw = 1, _sh = 1; if(inputs[| dimension_index].type == VALUE_TYPE.surface) { @@ -178,21 +146,65 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct _out[l] = surface_clone(_data[0], _out[l]); else _out[l] = _data[0]; - } else { + } else _out[l] = processData(_out[l], _data, outIndex, l); /// Process data - } } return _out; } #endregion - static update = function(frame = PROJECT.animator.current_frame) { #region - process_amount = 0; + static processBatchOutput = function() { #region + for(var i = 0; i < ds_list_size(outputs); i++) { + if(outputs[| i].type != VALUE_TYPE.surface) continue; + var _res = outputs[| i].getValue(); + surface_array_free(_res); + outputs[| i].setValue(noone); + } + + if(process_amount == 1) { + var data = processData(noone, inputs_data, 0, 0); + for(var i = 0; i < ds_list_size(outputs); i++) { + var _outp = array_safe_get(data, i, undefined); + if(_outp == undefined) continue; + outputs[| i].setValue(_outp); + } + } else { + var _outputs = array_create(ds_list_size(outputs)); + for( var l = 0; l < process_amount; l++ ) { + var _data = array_create(ds_list_size(inputs)); + for(var i = 0; i < ds_list_size(inputs); i++) + _data[i] = all_inputs[i][l]; + + var data = processData(_data, inputs_data, 0, l); + for(var i = 0; i < ds_list_size(outputs); i++) { + var _outp = array_safe_get(data, i, undefined); + _outputs[i][l] = _outp; + } + } + + for( var i = 0, n = ds_list_size(outputs); i < n; i++ ) + outputs[| i].setValue(_outputs[i]); + } + } #endregion + + static processOutput = function() { #region + for(var i = 0; i < ds_list_size(outputs); i++) { + if(outputs[| i].process_array) { + val = processDataArray(i); + if(val == undefined) continue; + } else + val = processData(noone, noone, i); + outputs[| i].setValue(val); + } + } #endregion + + static getInputs = function() { #region + process_amount = 1; inputs_data = array_create(ds_list_size(inputs)); inputs_is_array = array_create(ds_list_size(inputs)); process_length = array_create(ds_list_size(inputs)); - for(var i = 0; i < ds_list_size(inputs); i++) { //pre-collect current input data + for(var i = 0; i < ds_list_size(inputs); i++) { var val = inputs[| i].getValue(); var amo = inputs[| i].arrayLength(val); @@ -221,15 +233,41 @@ function Node_Processor(_x, _y, _group = noone) : Node(_x, _y, _group) construct process_length[i][1] = amoMax; } + for(var i = 0; i < ds_list_size(inputs); i++) + all_inputs[i] = array_create(process_amount); + + for(var l = 0; l < process_amount; l++) #region input preparation + for(var i = 0; i < ds_list_size(inputs); i++) { + var _in = inputs_data[i]; + + if(!inputs_is_array[i]) { + all_inputs[i][l] = _in; + continue; + } + + if(array_length(_in) == 0) { + all_inputs[i][l] = 0; + continue; + } + + var _index = 0; + switch(attributes.array_process) { + case ARRAY_PROCESS.loop : _index = safe_mod(l, array_length(_in)); break; + case ARRAY_PROCESS.hold : _index = min(l, array_length(_in) - 1); break; + case ARRAY_PROCESS.expand : _index = floor(l / process_length[i][1]) % process_length[i][0]; break; + case ARRAY_PROCESS.expand_inv : _index = floor(l / process_length[ds_list_size(inputs) - 1 - i][1]) % process_length[i][0]; break; + } + + all_inputs[i][l] = inputs[| i].arrayBalance(_in[_index]); + } #endregion + } #endregion + + static update = function(frame = PROJECT.animator.current_frame) { #region + getInputs(); + var val; - for(var i = 0; i < ds_list_size(outputs); i++) { - if(outputs[| i].process_array) { - val = preProcess(i); - if(val == undefined) continue; - } else - val = processData(noone, noone, i); - outputs[| i].setValue(val); - } + if(batch_output) processBatchOutput(); + else processOutput(); postUpdate(); } #endregion diff --git a/scripts/node_registry/node_registry.gml b/scripts/node_registry/node_registry.gml index 2162c1647..a762d6833 100644 --- a/scripts/node_registry/node_registry.gml +++ b/scripts/node_registry/node_registry.gml @@ -95,12 +95,13 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { global.RECENT_NODES = file_exists(recPath)? json_load_struct(recPath) : []; var group = ds_list_create(); - addNodeCatagory("Group", group, ["Node_Group"]); + addNodeCatagory("Group", group, ["Node_Group"]); #region ds_list_add(group, "Groups"); addNodeObject(group, "Input", s_node_group_input, "Node_Group_Input", [1, Node_Group_Input]); addNodeObject(group, "Output", s_node_group_output,"Node_Group_Output", [1, Node_Group_Output]); - - var iter = ds_list_create(); + #endregion + + var iter = ds_list_create(); #region addNodeCatagory("Loop", iter, ["Node_Iterate"]); ds_list_add(iter, "Groups"); addNodeObject(iter, "Input", s_node_loop_input, "Node_Iterator_Input", [1, Node_Iterator_Input]); @@ -109,8 +110,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(iter, "Loops"); addNodeObject(iter, "Index", s_node_iterator_index, "Node_Iterator_Index", [1, Node_Iterator_Index]); addNodeObject(iter, "Loop amount", s_node_iterator_amount, "Node_Iterator_Length", [1, Node_Iterator_Length]); - - var itere = ds_list_create(); + #endregion + + var itere = ds_list_create(); #region addNodeCatagory("Loop", itere, ["Node_Iterate_Each"]); ds_list_add(itere, "Groups"); addNodeObject(itere, "Input", s_node_group_input, "Node_Group_Input", [1, Node_Group_Input]); @@ -119,8 +121,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(itere, "Loops"); addNodeObject(itere, "Index", s_node_iterator_index, "Node_Iterator_Index", [1, Node_Iterator_Index]); addNodeObject(itere, "Array Length", s_node_iterator_length, "Node_Iterator_Each_Length", [1, Node_Iterator_Each_Length]); + #endregion - var filter = ds_list_create(); + var filter = ds_list_create(); #region addNodeCatagory("Filter", filter, ["Node_Iterate_Filter"]); ds_list_add(filter, "Groups"); addNodeObject(filter, "Input", s_node_group_input, "Node_Group_Input", [1, Node_Group_Input]); @@ -129,14 +132,16 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(filter, "Loops"); addNodeObject(filter, "Index", s_node_iterator_index, "Node_Iterator_Index", [1, Node_Iterator_Index]); addNodeObject(filter, "Array Length", s_node_iterator_length, "Node_Iterator_Each_Length", [1, Node_Iterator_Each_Length]); - - var feed = ds_list_create(); + #endregion + + var feed = ds_list_create(); #region addNodeCatagory("Feedback", feed, ["Node_Feedback"]); ds_list_add(feed, "Groups"); addNodeObject(feed, "Input", s_node_feedback_input, "Node_Feedback_Input", [1, Node_Feedback_Input]); addNodeObject(feed, "Output", s_node_feedback_output, "Node_Feedback_Output", [1, Node_Feedback_Output]); - - var vfx = ds_list_create(); + #endregion + + var vfx = ds_list_create(); #region addNodeCatagory("VFX", vfx, ["Node_VFX_Group"]); ds_list_add(vfx, "Groups"); addNodeObject(vfx, "Input", s_node_vfx_input, "Node_Group_Input", [1, Node_Group_Input]); @@ -158,8 +163,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(vfx, "Instance control"); addNodeObject(vfx, "VFX Variable", s_node_vfx_variable, "Node_VFX_Variable", [1, Node_VFX_Variable]).setVersion(1120); addNodeObject(vfx, "VFX Override", s_node_vfx_override, "Node_VFX_Override", [1, Node_VFX_Override]).setVersion(1120); - - var rigidSim = ds_list_create(); + #endregion + + var rigidSim = ds_list_create(); #region addNodeCatagory("RigidSim", rigidSim, ["Node_Rigid_Group"]); ds_list_add(rigidSim, "Group"); addNodeObject(rigidSim, "Input", s_node_group_input, "Node_Group_Input", [1, Node_Group_Input]); @@ -175,8 +181,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(rigidSim, "Activate Physics", s_node_rigidSim_activate, "Node_Rigid_Activate", [1, Node_Rigid_Activate]).setVersion(1110); addNodeObject(rigidSim, "Rigidbody Variable", s_node_rigid_variable, "Node_Rigid_Variable", [1, Node_Rigid_Variable]).setVersion(1120); addNodeObject(rigidSim, "Rigidbody Override", s_node_rigid_override, "Node_Rigid_Override", [1, Node_Rigid_Override]).setVersion(1120); - - var fluidSim = ds_list_create(); + #endregion + + var fluidSim = ds_list_create(); #region addNodeCatagory("FluidSim", fluidSim, ["Node_Fluid_Group"]); ds_list_add(fluidSim, "Group"); addNodeObject(fluidSim, "Input", s_node_group_input, "Node_Group_Input", [1, Node_Group_Input]); @@ -195,8 +202,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(fluidSim, "Vortex", s_node_fluidSim_vortex, "Node_Fluid_Vortex", [1, Node_Fluid_Vortex]).setVersion(1120); addNodeObject(fluidSim, "Repulse", s_node_fluidSim_repulse, "Node_Fluid_Repulse", [1, Node_Fluid_Repulse]).setVersion(1120); addNodeObject(fluidSim, "Turbulence", s_node_fluidSim_turbulence, "Node_Fluid_Turbulence", [1, Node_Fluid_Turbulence]).setVersion(1120); - - var strandSim = ds_list_create(); + #endregion + + var strandSim = ds_list_create(); #region addNodeCatagory("StrandSim", strandSim, ["Node_Strand_Group"]); ds_list_add(strandSim, "Group"); addNodeObject(strandSim, "Input", s_node_group_input, "Node_Group_Input", [1, Node_Group_Input]); @@ -214,14 +222,15 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(strandSim, "Strand Break", s_node_strandSim_break, "Node_Strand_Break", [1, Node_Strand_Break]).setVersion(1140); addNodeObject(strandSim, "Strand Length Adjust", s_node_strandSim_length, "Node_Strand_Length_Adjust", [1, Node_Strand_Length_Adjust]).setVersion(1140); addNodeObject(strandSim, "Strand Collision", s_node_strandSim_collide, "Node_Strand_Collision", [1, Node_Strand_Collision]).setVersion(1140); - + #endregion + NODE_PAGE_DEFAULT = ds_list_size(NODE_CATEGORY); ADD_NODE_PAGE = NODE_PAGE_DEFAULT; var fav = ds_list_create(); addNodeCatagory("Favourites", fav); - var input = ds_list_create(); + var input = ds_list_create(); #region addNodeCatagory("IO", input); ds_list_add(input, "Images"); addNodeObject(input, "Canvas", s_node_canvas, "Node_Canvas", [1, Node_Canvas], ["draw"], "Draw on surface using brush, eraser, etc.") @@ -248,8 +257,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(input, "Network"); addNodeObject(input, "Websocket Receiver", s_node_websocket_receive, "Node_Websocket_Receiver", [1, Node_Websocket_Receiver],, "Create websocket server to receive data from the network.").setVersion(1145); addNodeObject(input, "Websocket Sender", s_node_websocket_send, "Node_Websocket_Sender", [1, Node_Websocket_Sender],, "Create websocket server to send data to the network.").setVersion(1145); - - var transform = ds_list_create(); + #endregion + + var transform = ds_list_create(); #region addNodeCatagory("Transform", transform); ds_list_add(transform, "Transformations"); addNodeObject(transform, "Transform", s_node_transform, "Node_Transform", [1, Node_Transform], ["move", "rotate", "scale"], "Move, rotate, and scale image."); @@ -270,8 +280,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(transform, "Composite", s_node_compose, "Node_Composite", [1, Node_Composite], ["merge"], "Combine multiple images with controllable position, rotation, scale."); addNodeObject(transform, "Nine Slice", s_node_9patch, "Node_9Slice", [1, Node_9Slice], ["9 slice", "splice"], "Cut image into 3x3 parts, and scale/repeat only the middle part."); addNodeObject(transform, "Padding", s_node_padding, "Node_Padding", [1, Node_Padding],, "Make image bigger by adding space in 4 directions."); - - var filter = ds_list_create(); + #endregion + + var filter = ds_list_create(); #region addNodeCatagory("Filter", filter); ds_list_add(filter, "Combines"); addNodeObject(filter, "Blend", s_node_blend, "Node_Blend", [0, Node_create_Blend], ["normal", "add", "subtract", "multiply", "screen", "maxx", "minn"], "Blend 2 images using different blendmodes."); @@ -345,48 +356,51 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(filter, "Fixes"); addNodeObject(filter, "De-Corner", s_node_decorner, "Node_De_Corner", [1, Node_De_Corner], ["decorner"], "Attempt to remove single pixel corner from the image."); addNodeObject(filter, "De-Stray", s_node_destray, "Node_De_Stray", [1, Node_De_Stray], ["destray"], "Attempt to remove orphan pixel."); + #endregion + + var d3d = ds_list_create(); #region + addNodeCatagory("3D", d3d); + ds_list_add(d3d, "2D Operations"); + addNodeObject(d3d, "Normal", s_node_normal, "Node_Normal", [1, Node_Normal],, "Create normal map using greyscale value as height."); + addNodeObject(d3d, "Normal Light", s_node_normal_light, "Node_Normal_Light", [1, Node_Normal_Light],, "Light up the image using normal mapping."); + addNodeObject(d3d, "Bevel", s_node_bevel, "Node_Bevel", [1, Node_Bevel], ["shade", "auto shade"], "Apply 2D bevel on the image."); + addNodeObject(d3d, "Sprite Stack", s_node_stack, "Node_Sprite_Stack", [1, Node_Sprite_Stack],, "Create sprite stack either from repeating a single image or stacking different images using array."); - var threeD = ds_list_create(); - addNodeCatagory("3D", threeD); - ds_list_add(threeD, "2D Operations"); - addNodeObject(threeD, "Normal", s_node_normal, "Node_Normal", [1, Node_Normal],, "Create normal map using greyscale value as height."); - addNodeObject(threeD, "Normal Light", s_node_normal_light, "Node_Normal_Light", [1, Node_Normal_Light],, "Light up the image using normal mapping."); - addNodeObject(threeD, "Bevel", s_node_bevel, "Node_Bevel", [1, Node_Bevel], ["shade", "auto shade"], "Apply 2D bevel on the image."); - addNodeObject(threeD, "Sprite Stack", s_node_stack, "Node_Sprite_Stack", [1, Node_Sprite_Stack],, "Create sprite stack either from repeating a single image or stacking different images using array."); + ds_list_add(d3d, "3D"); + addNodeObject(d3d, "3D Scene", s_node_3d_cube, "Node_3D_Scene", [1, Node_3D_Scene]); + addNodeObject(d3d, "3D Camera", s_node_3d_cube, "Node_3D_Camera", [1, Node_3D_Camera]); - ds_list_add(threeD, "3D"); - addNodeObject(threeD, "3D Scene", s_node_3d_cube, "Node_3D_Scene", [1, Node_3D_Scene]); - addNodeObject(threeD, "3D Camera", s_node_3d_cube, "Node_3D_Camera", [1, Node_3D_Camera]); + ds_list_add(d3d, "Mesh"); + addNodeObject(d3d, "3D Object", s_node_3d_obj, "Node_3D_Mesh_Obj", [0, Node_create_3D_Obj],, "Load .obj file from your computer as a 3D object."); + addNodeObject(d3d, "3D Plane", s_node_3d_plane, "Node_3D_Mesh_Plane", [1, Node_3D_Mesh_Plane],, "Put 2D image on a plane in 3D space."); + addNodeObject(d3d, "3D Cube", s_node_3d_cube, "Node_3D_Mesh_Cube", [1, Node_3D_Mesh_Cube]); + addNodeObject(d3d, "3D Cylinder", s_node_3d_cylinder, "Node_3D_Mesh_Cylinder", [1, Node_3D_Mesh_Cylinder]); + addNodeObject(d3d, "3D UV Sphere", s_node_3d_sphere, "Node_3D_Mesh_Sphere_UV", [1, Node_3D_Mesh_Sphere_UV]); + addNodeObject(d3d, "3D Icosphere", s_node_3d_sphere, "Node_3D_Mesh_Sphere_Ico", [1, Node_3D_Mesh_Sphere_Ico]); + addNodeObject(d3d, "3D Cone", s_node_3d_cone, "Node_3D_Mesh_Cone", [1, Node_3D_Mesh_Cone]) + addNodeObject(d3d, "Surface Extrude", s_node_3d_extrude, "Node_3D_Mesh_Extrude", [1, Node_3D_Mesh_Extrude],, "Extrude 2D image into 3D object."); - ds_list_add(threeD, "Mesh"); - addNodeObject(threeD, "3D Object", s_node_3d_obj, "Node_3D_Mesh_Obj", [0, Node_create_3D_Obj],, "Load .obj file from your computer as a 3D object."); - addNodeObject(threeD, "3D Plane", s_node_3d_plane, "Node_3D_Plane", [1, Node_3D_Mesh_Plane],, "Put 2D image on a plane in 3D space."); - addNodeObject(threeD, "3D Cube", s_node_3d_cube, "Node_3D_Mesh_Cube", [1, Node_3D_Mesh_Cube]); - addNodeObject(threeD, "3D Cylinder", s_node_3d_cylinder, "Node_3D_Mesh_Cylinder", [1, Node_3D_Mesh_Cylinder]); - addNodeObject(threeD, "3D UV Sphere", s_node_3d_sphere, "Node_3D_Mesh_Sphere_UV", [1, Node_3D_Mesh_Sphere_UV]); - addNodeObject(threeD, "3D Icosphere", s_node_3d_sphere, "Node_3D_Mesh_Sphere_Ico", [1, Node_3D_Mesh_Sphere_Ico]); - addNodeObject(threeD, "3D Cone", s_node_3d_cone, "Node_3D_Mesh_Cone", [1, Node_3D_Mesh_Cone]) + ds_list_add(d3d, "Light"); + addNodeObject(d3d, "Directional Light", s_node_3d_cube, "Node_3D_Light_Directional", [1, Node_3D_Light_Directional]); + addNodeObject(d3d, "Point Light", s_node_3d_cube, "Node_3D_Light_Point", [1, Node_3D_Light_Point]); - ds_list_add(threeD, "Light"); - addNodeObject(threeD, "Directional Light", s_node_3d_cube, "Node_3D_Light_Directional", [1, Node_3D_Light_Directional]); - addNodeObject(threeD, "Point Light", s_node_3d_cube, "Node_3D_Light_Point", [1, Node_3D_Light_Point]); + ds_list_add(d3d, "Legacy"); ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + addNodeObject(d3d, "3D Plane", s_node_3d_plane, "Node_3D_Plane", [1, Node_3D_Plane],, "Put 2D image on a plane in 3D space.").isDeprecated(); + addNodeObject(d3d, "3D Cube", s_node_3d_cube, "Node_3D_Cube", [1, Node_3D_Cube]).isDeprecated(); + addNodeObject(d3d, "3D Cylinder", s_node_3d_cylinder, "Node_3D_Cylinder", [1, Node_3D_Cylinder]).isDeprecated(); + addNodeObject(d3d, "3D Sphere", s_node_3d_sphere, "Node_3D_Sphere", [1, Node_3D_Sphere]).setVersion(1090).isDeprecated(); + addNodeObject(d3d, "3D Cone", s_node_3d_cone, "Node_3D_Cone", [1, Node_3D_Cone]).setVersion(1090).isDeprecated(); + addNodeObject(d3d, "3D Extrude", s_node_3d_extrude, "Node_3D_Extrude", [1, Node_3D_Extrude],, "Extrude 2D image into 3D object.").isDeprecated(); - ds_list_add(threeD, "Legacy"); ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - addNodeObject(threeD, "3D Plane", s_node_3d_plane, "Node_3D_Plane", [1, Node_3D_Plane],, "Put 2D image on a plane in 3D space.").isDeprecated(); - addNodeObject(threeD, "3D Cube", s_node_3d_cube, "Node_3D_Cube", [1, Node_3D_Cube]).isDeprecated(); - addNodeObject(threeD, "3D Cylinder", s_node_3d_cylinder, "Node_3D_Cylinder", [1, Node_3D_Cylinder]).isDeprecated(); - addNodeObject(threeD, "3D Sphere", s_node_3d_sphere, "Node_3D_Sphere", [1, Node_3D_Sphere]).setVersion(1090).isDeprecated(); - addNodeObject(threeD, "3D Cone", s_node_3d_cone, "Node_3D_Cone", [1, Node_3D_Cone]).setVersion(1090).isDeprecated(); - addNodeObject(threeD, "3D Extrude", s_node_3d_extrude, "Node_3D_Extrude", [1, Node_3D_Extrude],, "Extrude 2D image into 3D object.").isDeprecated(); + addNodeObject(d3d, "3D Transform", s_node_3d_transform, "Node_3D_Transform", [1, Node_3D_Transform]).setVersion(1080).isDeprecated(); + addNodeObject(d3d, "3D Combine", s_node_3d_obj_combine, "Node_3D_Combine", [1, Node_3D_Combine],, "Combine multiple 3D object to a single scene,").setVersion(1080).isDeprecated(); + addNodeObject(d3d, "3D Repeat", s_node_3d_array, "Node_3D_Repeat", [1, Node_3D_Repeat], ["3d array"], "Repeat 3D object multiple times.").setVersion(1080).isDeprecated(); + addNodeObject(d3d, "3D Displace", s_node_3d_displace, "Node_3D_Displace", [1, Node_3D_Displace]).setVersion(1143).isDeprecated(); - addNodeObject(threeD, "3D Transform", s_node_3d_transform, "Node_3D_Transform", [1, Node_3D_Transform]).setVersion(1080).isDeprecated(); - addNodeObject(threeD, "3D Combine", s_node_3d_obj_combine, "Node_3D_Combine", [1, Node_3D_Combine],, "Combine multiple 3D object to a single scene,").setVersion(1080).isDeprecated(); - addNodeObject(threeD, "3D Repeat", s_node_3d_array, "Node_3D_Repeat", [1, Node_3D_Repeat], ["3d array"], "Repeat 3D object multiple times.").setVersion(1080).isDeprecated(); - addNodeObject(threeD, "3D Displace", s_node_3d_displace, "Node_3D_Displace", [1, Node_3D_Displace]).setVersion(1143).isDeprecated(); - - addNodeObject(threeD, "3D Export", s_node_3d_export, "Node_3D_Export", [1, Node_3D_Export]).setVersion(1143).isDeprecated(); - - var generator = ds_list_create(); + addNodeObject(d3d, "3D Export", s_node_3d_export, "Node_3D_Export", [1, Node_3D_Export]).setVersion(1143).isDeprecated(); + #endregion + + var generator = ds_list_create(); #region addNodeCatagory("Generate", generator); ds_list_add(generator, "Colors"); addNodeObject(generator, "Solid", s_node_solid, "Node_Solid", [1, Node_Solid],, "Create image of a single color."); @@ -436,8 +450,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(generator, "Others"); addNodeObject(generator, "Flood Fill", s_node_flood_fill, "Node_Flood_Fill", [1, Node_Flood_Fill],, "Filled connected pixel given position and color.").setVersion(1133); addNodeObject(generator, "Bar / Graph", s_node_bar_graph, "Node_Plot_Linear", [1, Node_Plot_Linear], ["graph", "waveform", "bar chart", "plot"], "Plot graph or bar chart from array of number.").setVersion(1144); - - var compose = ds_list_create(); + #endregion + + var compose = ds_list_create(); #region addNodeCatagory("Compose", compose); ds_list_add(compose, "Composes"); addNodeObject(compose, "Blend", s_node_blend, "Node_Blend", [1, Node_Blend]); @@ -458,8 +473,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(compose, "Export"); addNodeObject(compose, "Export", s_node_export, "Node_Export", [0, Node_create_Export]); } - - var values = ds_list_create(); + #endregion + + var values = ds_list_create(); #region addNodeCatagory("Values", values); ds_list_add(values, "Raw data"); addNodeObject(values, "Number", s_node_number, "Node_Number", [1, Node_Number]); @@ -568,8 +584,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(values, "Buffer"); addNodeObject(values, "Buffer from Surface", s_node_surface_to_buffer, "Node_Surface_To_Buffer", [1, Node_Surface_To_Buffer], ["surface to buffer"], "Create buffer from surface.").setVersion(1146); - - var color = ds_list_create(); + #endregion + + var color = ds_list_create(); #region addNodeCatagory("Color", color); ds_list_add(color, "Colors"); addNodeObject(color, "Color", s_node_color_out, "Node_Color", [1, Node_Color]); @@ -592,8 +609,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(color, "Gradient Shift", s_node_gradient_shift, "Node_Gradient_Shift", [1, Node_Gradient_Shift],, "Move gradients keys."); addNodeObject(color, "Gradient Replace", s_node_gradient_replace, "Node_Gradient_Replace_Color", [1, Node_Gradient_Replace_Color]).setVersion(1135); addNodeObject(color, "Gradient Data", s_node_gradient_data, "Node_Gradient_Extract", [1, Node_Gradient_Extract],, "Get palatte and array of key positions from gradient.").setVersion(1135); - - var animation = ds_list_create(); + #endregion + + var animation = ds_list_create(); #region addNodeCatagory("Animation", animation); ds_list_add(animation, "Animations"); addNodeObject(animation, "Frame Index", s_node_counter, "Node_Counter", [1, Node_Counter], ["current frame", "counter"], "Output current frame as frame index, or animation progress (0 - 1)."); @@ -607,8 +625,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(animation, "FFT", s_node_FFT, "Node_FFT", [1, Node_FFT], ["frequency analysis"], "Perform fourier transform on number array.").setVersion(1144); addNodeObject(animation, "Bar / Graph", s_node_bar_graph, "Node_Plot_Linear", [1, Node_Plot_Linear], ["graph", "waveform", "bar chart", "plot"], "Plot graph or bar chart from array of number.").setVersion(1144); addNodeObject(animation, "Audio Window", s_node_audio_trim, "Node_Audio_Window", [1, Node_Audio_Window],, "Take a slice of an audio array based on the current frame.").setVersion(1144); - - var node = ds_list_create(); + #endregion + + var node = ds_list_create(); #region addNodeCatagory("Node", node); ds_list_add(node, "Control"); addNodeObject(node, "Condition", s_node_condition, "Node_Condition", [1, Node_Condition],, "Given a condition, output one value if true, another value is false."); @@ -641,7 +660,8 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { ds_list_add(node, "Debug"); addNodeObject(node, "Print", s_node_print, "Node_Print", [1, Node_Print], ["debug log"], "Display text to notification.").setVersion(1145); - + #endregion + var actions = ds_list_create(); addNodeCatagory("Actions", actions); __initNodeActions(actions); @@ -652,7 +672,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { //////////////////////////////////////////////////////////////// PIXEL BUILDER //////////////////////////////////////////////////////////////// - var pb_draw = ds_list_create(); + var pb_draw = ds_list_create(); #region addNodePBCatagory("Draw", pb_draw); ds_list_add(pb_draw, "Fill"); addNodeObject(pb_draw, "Fill", s_node_pb_draw_fill, "Node_PB_Draw_Fill", [1, Node_PB_Draw_Fill]); @@ -667,8 +687,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(pb_draw, "Line", s_node_pb_draw_line, "Node_PB_Draw_Line", [1, Node_PB_Draw_Line]); addNodeObject(pb_draw, "Angle", s_node_pb_draw_angle, "Node_PB_Draw_Angle", [1, Node_PB_Draw_Angle]); addNodeObject(pb_draw, "Blob", s_node_pb_draw_blob, "Node_PB_Draw_Blob", [1, Node_PB_Draw_Blob]); - - var pb_box = ds_list_create(); + #endregion + + var pb_box = ds_list_create(); #region addNodePBCatagory("Box", pb_box); ds_list_add(pb_box, "Layer"); addNodeObject(pb_box, "Layer", s_node_pb_layer, "Node_PB_Layer", [1, Node_PB_Layer]); @@ -681,8 +702,9 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(pb_box, "Divide", s_node_pb_box_divide, "Node_PB_Box_Divide", [1, Node_PB_Box_Divide]); addNodeObject(pb_box, "Divide Grid", s_node_pb_box_divide_grid, "Node_PB_Box_Divide_Grid", [1, Node_PB_Box_Divide_Grid]); addNodeObject(pb_box, "Contract", s_node_pb_box_contract, "Node_PB_Box_Contract", [1, Node_PB_Box_Contract]); - - var pb_fx = ds_list_create(); + #endregion + + var pb_fx = ds_list_create(); #region addNodePBCatagory("Effects", pb_fx); ds_list_add(pb_fx, "Effect"); addNodeObject(pb_fx, "Outline", s_node_pb_fx_outline, "Node_PB_Fx_Outline", [1, Node_PB_Fx_Outline]); @@ -702,16 +724,18 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(pb_fx, "Add", s_node_pb_fx_add, "Node_PB_Fx_Add", [1, Node_PB_Fx_Add]); addNodeObject(pb_fx, "Subtract", s_node_pb_fx_subtract, "Node_PB_Fx_Subtract", [1, Node_PB_Fx_Subtract]); addNodeObject(pb_fx, "Intersect", s_node_pb_fx_interesct, "Node_PB_Fx_Intersect", [1, Node_PB_Fx_Intersect]); - - var pb_arr = ds_list_create(); + #endregion + + var pb_arr = ds_list_create(); #region addNodePBCatagory("Array", pb_arr); addNodeObject(pb_arr, "Array", s_node_array, "Node_Array", [1, Node_Array]); addNodeObject(pb_arr, "Array Get", s_node_array_get, "Node_Array_Get", [1, Node_Array_Get], ["get array"]); addNodeObject(pb_arr, "Array Set", s_node_array_set, "Node_Array_Set", [1, Node_Array_Set], ["set array"]).setVersion(1120); addNodeObject(pb_arr, "Array Insert", s_node_array_insert, "Node_Array_Insert", [1, Node_Array_Insert], ["insert array"]).setVersion(1120); addNodeObject(pb_arr, "Array Remove", s_node_array_remove, "Node_Array_Remove", [1, Node_Array_Remove], ["remove array", "delete array", "array delete"]).setVersion(1120); - - var hid = ds_list_create(); + #endregion + + var hid = ds_list_create(); #region addNodeCatagory("Hidden", hid, ["Hidden"]); addNodeObject(hid, "Input", s_node_loop_input, "Node_Iterator_Each_Input", [1, Node_Iterator_Each_Input]); addNodeObject(hid, "Output", s_node_loop_output, "Node_Iterator_Each_Output", [1, Node_Iterator_Each_Output]); @@ -724,6 +748,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { addNodeObject(hid, "Sort Output", s_node_grid_hex_noise, "Node_Iterator_Sort_Output", [1, Node_Iterator_Sort_Output]); addNodeObject(hid, "Onion Skin", s_node_cache, "Node_Onion_Skin", [1, Node_Onion_Skin]).setVersion(1147); addNodeObject(hid, "Pixel Builder", s_node_pixel_builder, "Node_Pixel_Builder", [1, Node_Pixel_Builder]).setVersion(1150); + #endregion } #endregion diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index 54c67c3a9..ddc5e1467 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -50,6 +50,7 @@ enum VALUE_TYPE { d3Light = 27, d3Camera = 28, d3Scene = 29, + d3Material = 30, action = 99, } @@ -153,6 +154,7 @@ function value_color(i) { #region $ffa64d, //d3Light $ffa64d, //d3Camera $ffa64d, //d3Scene + $ffa64d, //d3Material ]; if(i == 99) return $5dde8f; @@ -221,6 +223,8 @@ function value_type_directional(f, t) { #region if(f == VALUE_TYPE.color && t == VALUE_TYPE.struct ) return true; if(f == VALUE_TYPE.mesh && t == VALUE_TYPE.struct ) return true; + if(f == VALUE_TYPE.surface && t == VALUE_TYPE.d3Material ) return true; + return false; } #endregion @@ -1038,28 +1042,30 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru var typeFrom = nodeFrom.type; var display = nodeFrom.display_type; - if(type == VALUE_TYPE.gradient && typeFrom == VALUE_TYPE.color) { - if(is_struct(value) && instanceof(value) == "gradientObject") - return value; - if(is_array(value)) { - var amo = array_length(value); - var grad = array_create(amo); - for( var i = 0; i < amo; i++ ) - grad[i] = new gradientKey(i / amo, value[i]); - var g = new gradientObject(); - g.keys = grad; - return g; - } + #region color compatibility [ color, palette, gradient ] + if(type == VALUE_TYPE.gradient && typeFrom == VALUE_TYPE.color) { + if(is_struct(value) && instanceof(value) == "gradientObject") + return value; + if(is_array(value)) { + var amo = array_length(value); + var grad = array_create(amo); + for( var i = 0; i < amo; i++ ) + grad[i] = new gradientKey(i / amo, value[i]); + var g = new gradientObject(); + g.keys = grad; + return g; + } - var grad = new gradientObject(value); - return grad; - } + var grad = new gradientObject(value); + return grad; + } - if(display_type == VALUE_DISPLAY.palette && !is_array(value)) { - return [ value ]; - } + if(display_type == VALUE_DISPLAY.palette && !is_array(value)) { + return [ value ]; + } + #endregion - if(display_type == VALUE_DISPLAY.area) { + if(display_type == VALUE_DISPLAY.area) { #region var dispType = struct_try_get(nodeFrom.extra_data, "area_type", AREA_MODE.area); var surfGet = nodeFrom.display_data; if(!applyUnit || surfGet == -1) { @@ -1089,20 +1095,17 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru var sh = abs(value[1] - value[3]) / 2; return [cx, cy, sw, sh, value[4]]; } - } + } #endregion - - if(type == VALUE_TYPE.text) { + if(type == VALUE_TYPE.text) { #region switch(display_type) { - case VALUE_DISPLAY.text_array : - return value; - default: - return string_real(value); + case VALUE_DISPLAY.text_array : return value; + default: return string_real(value); } - } + } #endregion - if(typeFrom == VALUE_TYPE.integer && type == VALUE_TYPE.color) - return value; + if(typeFrom == VALUE_TYPE.surface && type == VALUE_TYPE.d3Material) + return new __d3dMaterial(value); if((typeFrom == VALUE_TYPE.integer || typeFrom == VALUE_TYPE.float || typeFrom == VALUE_TYPE.boolean) && type == VALUE_TYPE.color) return value >= 1? value : make_color_hsv(0, 0, value * 255); diff --git a/scripts/obj_reader/obj_reader.gml b/scripts/obj_reader/obj_reader.gml index e0a86e027..77227778d 100644 --- a/scripts/obj_reader/obj_reader.gml +++ b/scripts/obj_reader/obj_reader.gml @@ -164,8 +164,7 @@ function readObj(path, flipUV = false) { var tri = tris[i]; var _flen = ds_list_size(face); - var _v = array_create(tri * 3); - var _vind = 0; + var _v = ds_list_create(); for(var j = 0; j < _flen; j++) { var _f = face[| j]; @@ -190,22 +189,22 @@ function readObj(path, flipUV = false) { if(_vlen >= 3) { vertex_add_pntc(VB, _pf[0], _pfn[0], _pft[0]); - vertex_add_pntc(VB, _pf[1], _pfn[1], _pft[1]); vertex_add_pntc(VB, _pf[2], _pfn[2], _pft[2]); + vertex_add_pntc(VB, _pf[1], _pfn[1], _pft[1]); - _v[_vind] = V3(_pf[0]).setNormal(_pfn[0]).setUV(_pft[0]); _vind++; - _v[_vind] = V3(_pf[1]).setNormal(_pfn[1]).setUV(_pft[1]); _vind++; - _v[_vind] = V3(_pf[2]).setNormal(_pfn[2]).setUV(_pft[2]); _vind++; + ds_list_add(_v, V3(_pf[0]).setNormal(_pfn[0]).setUV(_pft[0])); + ds_list_add(_v, V3(_pf[2]).setNormal(_pfn[2]).setUV(_pft[2])); + ds_list_add(_v, V3(_pf[1]).setNormal(_pfn[1]).setUV(_pft[1])); } if(_vlen >= 4) { vertex_add_pntc(VB, _pf[0], _pfn[0], _pft[0]); - vertex_add_pntc(VB, _pf[2], _pfn[2], _pft[2]); vertex_add_pntc(VB, _pf[3], _pfn[3], _pft[3]); + vertex_add_pntc(VB, _pf[2], _pfn[2], _pft[2]); - _v[_vind] = V3(_pf[0]).setNormal(_pfn[0]).setUV(_pft[0]); _vind++; - _v[_vind] = V3(_pf[2]).setNormal(_pfn[2]).setUV(_pft[2]); _vind++; - _v[_vind] = V3(_pf[3]).setNormal(_pfn[3]).setUV(_pft[3]); _vind++; + ds_list_add(_v, V3(_pf[0]).setNormal(_pfn[0]).setUV(_pft[0])); + ds_list_add(_v, V3(_pf[3]).setNormal(_pfn[3]).setUV(_pft[3])); + ds_list_add(_v, V3(_pf[2]).setNormal(_pfn[2]).setUV(_pft[2])); } } @@ -213,7 +212,8 @@ function readObj(path, flipUV = false) { vertex_freeze(VB); VBS[i] = VB; - V[i] = _v; + V[i] = ds_list_to_array(_v); + ds_list_destroy(_v); } #endregion diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index b973c2222..a0a586c91 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -80,21 +80,34 @@ function Panel_Preview() : PanelContent() constructor { tool_x_to = 0; tool_x_max = 0; tool_current = noone; + + sbChannel = new scrollBox([], function(index) { #region + var node = getNodePreview(); + if(node == noone) return; + + node.preview_channel = array_safe_get(sbChannelIndex, index); + }); #endregion + sbChannelIndex = []; + sbChannel.align = fa_left; #endregion #region ---- 3d ---- d3_active = false; _d3_active = false; d3_active_transition = 0; + d3_surface = noone; - d3_outline_surface = noone; + d3_surface_normal = noone; + d3_surface_depth = noone; + d3_surface_outline = noone; + d3_preview_channel = 0; #region camera d3_view_camera = new __3dCamera(); d3_camW = 1; d3_camH = 1; - d3_view_camera.setFocusAngle(135, 45, 16); + d3_view_camera.setFocusAngle(135, 45, 4); d3_camLerp = false; d3_camTarget = new __vec3(); @@ -117,7 +130,7 @@ function Panel_Preview() : PanelContent() constructor { d3_scene_light0.position.set(-1, -2, 3); d3_scene_light0.color = $FFFFFF; d3_scene_light0.shadow_active = false; - d3_scene_light0.shadow_map_scale = 128; + d3_scene_light0.shadow_map_scale = 4; d3_scene_light1 = new __3dLightDirectional(); d3_scene_light1.position.set(1, 2, -3); @@ -133,6 +146,12 @@ function Panel_Preview() : PanelContent() constructor { #region shadow map #endregion + + #region view channel + d3ChannelNames = [ "Rendered", "Normal", "Depth" ]; + d3Channel = new scrollBox(d3ChannelNames, function(index) { d3_preview_channel = index; }); + d3Channel.align = fa_left; + #endregion #endregion tb_framerate = new textBox(TEXTBOX_INPUT.number, function(val) { preview_rate = real(val); }); @@ -498,15 +517,6 @@ function Panel_Preview() : PanelContent() constructor { canvas_y = h / 2 - bbox.h * canvas_s / 2 - bbox.y0 * canvas_s; } #endregion - sbChannel = new scrollBox([], function(index) { #region - var node = getNodePreview(); - if(node == noone) return; - - node.preview_channel = array_safe_get(sbChannelIndex, index); - }); #endregion - - sbChannelIndex = []; - sbChannel.align = fa_left; function drawNodeChannel(_x, _y) { #region var _node = getNodePreview(); if(_node == noone) return; @@ -534,6 +544,18 @@ function Panel_Preview() : PanelContent() constructor { right_menu_y += ui(40); } #endregion + function drawNodeChannel3D(_x, _y) { #region + var _node = getNodePreview(); + if(_node == noone) return; + + var ww = ui(128); + var hh = toolbar_height - ui(12); + + d3Channel.setFocusHover(pFOCUS, pHOVER); + d3Channel.draw(_x - ww, _y - hh / 2, ww, hh, d3ChannelNames[d3_preview_channel], [mx, my], x, y); + right_menu_y += ui(40); + } #endregion + function drawOnionSkin(node, psx, psy, ss) { #region var _surf = preview_surface[0]; var _rang = PROJECT.onion_skin.range; @@ -780,6 +802,8 @@ function Panel_Preview() : PanelContent() constructor { #region shadow if(_prev_node.is_3D) { + d3_scene_light0.shadow_map_scale = d3_view_camera.focus_dist * 2; + var _prev_obj = _prev_node.getPreviewObject(); d3_scene_light0.shadowProjectVertex(d3_scene, _prev_obj); @@ -798,11 +822,16 @@ function Panel_Preview() : PanelContent() constructor { } #endregion + d3_surface = surface_verify(d3_surface, w, h); + d3_surface_normal = surface_verify(d3_surface_normal, w, h); + d3_surface_depth = surface_verify(d3_surface_depth, w, h); + d3_surface_outline = surface_verify(d3_surface_outline, w, h); + #region grid - d3_surface = surface_verify(d3_surface, w, h); - d3_outline_surface = surface_verify(d3_outline_surface, w, h); + surface_set_target_ext(0, d3_surface); + surface_set_target_ext(1, d3_surface_normal); + surface_set_target_ext(2, d3_surface_depth); - surface_set_target(d3_surface); draw_clear(bg_color); d3_view_camera.applyCamera(); @@ -828,6 +857,7 @@ function Panel_Preview() : PanelContent() constructor { #endregion #region draw + gpu_set_cullmode(cull_counterclockwise); if(_prev_node.is_3D) { var _prev_obj = _prev_node.getPreviewObject(); @@ -852,9 +882,16 @@ function Panel_Preview() : PanelContent() constructor { } } + gpu_set_cullmode(cull_noculling); surface_reset_target(); - draw_surface_safe(d3_surface); - //draw_surface_stretched(d3_scene_light0.shadow_map, 64, 64, 96, 96); + + switch(d3_preview_channel) { + case 0 : draw_surface_safe(d3_surface); break; + case 1 : draw_surface_safe(d3_surface_normal); break; + case 2 : draw_surface_safe(d3_surface_depth); break; + } + + //draw_surface_stretched_safe(d3_scene_light0.shadow_map, 64, 64, 128, 128); #endregion #region outline @@ -863,7 +900,7 @@ function Panel_Preview() : PanelContent() constructor { if(inspect_node && inspect_node.is_3D) { var _inspect_obj = inspect_node.getPreviewObjectOutline(); - surface_set_target(d3_outline_surface); + surface_set_target(d3_surface_outline); draw_clear(c_black); d3_view_camera.applyCamera(); @@ -876,9 +913,9 @@ function Panel_Preview() : PanelContent() constructor { surface_reset_target(); shader_set(sh_d3d_outline); - shader_set_dim("dimension", d3_outline_surface); + shader_set_dim("dimension", d3_surface_outline); shader_set_color("outlineColor", COLORS._main_accent); - draw_surface(d3_outline_surface, 0, 0); + draw_surface(d3_surface_outline, 0, 0); shader_reset(); } #endregion @@ -1256,7 +1293,9 @@ function Panel_Preview() : PanelContent() constructor { draw_set_color(COLORS.panel_toolbar_separator); draw_line_width(tbx + ui(12), tby - toolbar_height / 2 + ui(8), tbx + ui(12), tby + toolbar_height / 2 - ui(8), 2); - drawNodeChannel(tbx, tby); + + if(d3_active) drawNodeChannel3D(tbx, tby); + else drawNodeChannel(tbx, tby); } #endregion function drawSplitView() { #region diff --git a/scripts/surface_draw_functions/surface_draw_functions.gml b/scripts/surface_draw_functions/surface_draw_functions.gml index fb1a0fa29..5e8577a93 100644 --- a/scripts/surface_draw_functions/surface_draw_functions.gml +++ b/scripts/surface_draw_functions/surface_draw_functions.gml @@ -2,11 +2,9 @@ function __channel_pre(surf) { var f = surface_get_format(surf); switch(f) { - case surface_r8unorm : - case surface_r16float : - case surface_r32float : - shader_set(sh_draw_single_channel); - return; + case surface_r8unorm : shader_set(sh_draw_r8); return; + case surface_r16float : shader_set(sh_draw_r16); return; + case surface_r32float : shader_set(sh_draw_r32); return; } } diff --git a/shaders/sh_d3d_default/sh_d3d_default.fsh b/shaders/sh_d3d_default/sh_d3d_default.fsh index c21fd144d..68f94ce2c 100644 --- a/shaders/sh_d3d_default/sh_d3d_default.fsh +++ b/shaders/sh_d3d_default/sh_d3d_default.fsh @@ -5,7 +5,8 @@ varying vec2 v_vTexcoord; varying vec4 v_vColour; varying vec3 v_vNormal; -varying vec4 v_worldPosition; +varying vec4 v_worldPosition; +varying float v_cameraDistance; #region ---- light ---- uniform vec4 light_ambient; @@ -20,6 +21,7 @@ varying vec4 v_worldPosition; uniform mat4 light_dir_view[LIGHT_DIR_LIMIT]; uniform mat4 light_dir_proj[LIGHT_DIR_LIMIT]; uniform int light_dir_shadow_active[LIGHT_DIR_LIMIT]; + uniform float light_dir_shadow_bias[LIGHT_DIR_LIMIT]; uniform sampler2D light_dir_shadowmap_0; uniform sampler2D light_dir_shadowmap_1; uniform sampler2D light_dir_shadowmap_2; @@ -35,6 +37,7 @@ varying vec4 v_worldPosition; uniform mat4 light_pnt_view[96]; uniform mat4 light_pnt_proj[LIGHT_PNT_LIMIT]; uniform int light_pnt_shadow_active[LIGHT_PNT_LIMIT]; + uniform float light_pnt_shadow_bias[LIGHT_DIR_LIMIT]; uniform sampler2D light_pnt_shadowmap_0; uniform sampler2D light_pnt_shadowmap_1; uniform sampler2D light_pnt_shadowmap_2; @@ -93,7 +96,11 @@ float samplePntShadowMap(int index, vec2 position, int side) { void main() { vec4 final_color = texture2D( gm_BaseTexture, v_vTexcoord ); final_color *= v_vColour; - gl_FragColor = vec4(0.); + vec3 normal = normalize(v_vNormal); + + gl_FragData[0] = vec4(0.); + gl_FragData[1] = vec4(0.); + gl_FragData[2] = vec4(0.); #region ++++ light ++++ int shadow_map_index = 0; @@ -108,7 +115,8 @@ void main() { shadow_map_index = 0; for(int i = 0; i < light_dir_count; i++) { - light_dir_strength = dot(normalize(v_vNormal), normalize(light_dir_direction[i])); + vec3 lightVector = normalize(light_dir_direction[i]); + light_dir_strength = dot(normal, normalize(lightVector)); if(light_dir_strength < 0.) continue; @@ -122,11 +130,13 @@ void main() { light_map_depth = sampleDirShadowMap(shadow_map_index, lightMapPosition); shadow_map_index++; lightDistance = v_lightDistance; - - if(lightDistance > light_map_depth + shadowBias) + float shadowFactor = dot(normal, lightVector); + float bias = mix(light_dir_shadow_bias[i], 0., shadowFactor); + + if(lightDistance > light_map_depth + bias) continue; } - + light_dir_strength = max(light_dir_strength * light_dir_intensity[i], 0.); light_effect += light_dir_color[i].rgb * light_dir_strength; } @@ -138,34 +148,36 @@ void main() { shadow_map_index = 0; for(int i = 0; i < light_pnt_count; i++) { - light_pnt_strength = dot(normalize(v_vNormal), normalize(light_pnt_position[i] - v_worldPosition.xyz)); + vec3 lightVector = normalize(light_pnt_position[i] - v_worldPosition.xyz); + light_pnt_strength = dot(normal, lightVector); if(light_pnt_strength < 0.) continue; - light_distance = distance(light_pnt_position[i], v_worldPosition.xyz); + light_distance = length(lightVector); if(light_distance > light_pnt_radius[i]) continue; if(light_pnt_shadow_active[i] == 1) { - vec3 dir = v_worldPosition.xyz - light_pnt_position[i]; - vec3 dirAbs = abs(dir); + vec3 dirAbs = abs(lightVector); int side = dirAbs.x > dirAbs.y ? (dirAbs.x > dirAbs.z ? 0 : 2) : (dirAbs.y > dirAbs.z ? 1 : 2); side *= 2; - if(side == 0 && dir.x < 0.) side += 1; - else if(side == 2 && dir.y < 0.) side += 1; - else if(side == 4 && dir.z < 0.) side += 1; + if(side == 0 && lightVector.x < 0.) side += 1; + else if(side == 2 && lightVector.y < 0.) side += 1; + else if(side == 4 && lightVector.z < 0.) side += 1; vec4 cameraSpace = light_pnt_view[i * 6 + side] * v_worldPosition; vec4 screenSpace = light_pnt_proj[i] * cameraSpace; float v_lightDistance = screenSpace.z / screenSpace.w; vec2 lightMapPosition = (screenSpace.xy / screenSpace.w * 0.5) + 0.5; + float shadowFactor = dot(normal, lightVector); + float bias = mix(light_pnt_shadow_bias[i], 0., shadowFactor); light_map_depth = samplePntShadowMap(shadow_map_index, lightMapPosition, side); shadow_map_index++; - if(v_lightDistance > light_map_depth + shadowBias) + if(v_lightDistance > light_map_depth + bias) continue; } @@ -186,5 +198,7 @@ void main() { final_color.b = pow(final_color.b, 1. / 2.2); } - gl_FragColor = final_color; + gl_FragData[0] = final_color; + gl_FragData[1] = vec4(0.5 + normal * 0.5, 1.); + gl_FragData[2] = vec4(vec3(v_cameraDistance), 1.); } diff --git a/shaders/sh_d3d_default/sh_d3d_default.vsh b/shaders/sh_d3d_default/sh_d3d_default.vsh index 860fe48f4..b3cd0ad18 100644 --- a/shaders/sh_d3d_default/sh_d3d_default.vsh +++ b/shaders/sh_d3d_default/sh_d3d_default.vsh @@ -9,8 +9,11 @@ attribute vec2 in_TextureCoord; // (u,v) varying vec2 v_vTexcoord; varying vec4 v_vColour; varying vec3 v_vNormal; - varying vec4 v_worldPosition; +varying float v_cameraDistance; + +uniform float planeNear; +uniform float planeFar; void main() { vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); @@ -22,4 +25,7 @@ void main() { vec3 worldNormal = normalize(gm_Matrices[MATRIX_WORLD] * vec4(in_Normal, 0.)).xyz; v_vNormal = worldNormal; + + float ndcDepth = (gl_Position.z - planeNear - planeFar) / (planeFar - planeNear); + v_cameraDistance = ndcDepth * 0.5 + 0.5; } diff --git a/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh b/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh index ee4037620..b9c3dc9ac 100644 --- a/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh +++ b/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh @@ -2,4 +2,5 @@ varying float v_LightDepth; void main() { gl_FragColor = vec4(v_LightDepth, v_LightDepth, v_LightDepth, 1.); + //gl_FragColor = vec4(1.); } diff --git a/shaders/sh_draw_r16/sh_draw_r16.fsh b/shaders/sh_draw_r16/sh_draw_r16.fsh new file mode 100644 index 000000000..fced90f65 --- /dev/null +++ b/shaders/sh_draw_r16/sh_draw_r16.fsh @@ -0,0 +1,10 @@ +// +// Simple passthrough fragment shader +// +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() { + vec4 col = texture2D( gm_BaseTexture, v_vTexcoord ); + gl_FragColor = vec4(vec3(col.r), 1.); +} diff --git a/shaders/sh_draw_r16/sh_draw_r16.vsh b/shaders/sh_draw_r16/sh_draw_r16.vsh new file mode 100644 index 000000000..d4b316559 --- /dev/null +++ b/shaders/sh_draw_r16/sh_draw_r16.vsh @@ -0,0 +1,18 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() { + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_draw_r16/sh_draw_r16.yy b/shaders/sh_draw_r16/sh_draw_r16.yy new file mode 100644 index 000000000..cd775b26b --- /dev/null +++ b/shaders/sh_draw_r16/sh_draw_r16.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_draw_r16", + "parent": { + "name": "draw", + "path": "folders/shader/draw.yy", + }, + "type": 1, +} \ No newline at end of file diff --git a/shaders/sh_draw_r32/sh_draw_r32.fsh b/shaders/sh_draw_r32/sh_draw_r32.fsh new file mode 100644 index 000000000..fced90f65 --- /dev/null +++ b/shaders/sh_draw_r32/sh_draw_r32.fsh @@ -0,0 +1,10 @@ +// +// Simple passthrough fragment shader +// +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() { + vec4 col = texture2D( gm_BaseTexture, v_vTexcoord ); + gl_FragColor = vec4(vec3(col.r), 1.); +} diff --git a/shaders/sh_draw_r32/sh_draw_r32.vsh b/shaders/sh_draw_r32/sh_draw_r32.vsh new file mode 100644 index 000000000..d4b316559 --- /dev/null +++ b/shaders/sh_draw_r32/sh_draw_r32.vsh @@ -0,0 +1,18 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() { + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_draw_r32/sh_draw_r32.yy b/shaders/sh_draw_r32/sh_draw_r32.yy new file mode 100644 index 000000000..6989461a2 --- /dev/null +++ b/shaders/sh_draw_r32/sh_draw_r32.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_draw_r32", + "parent": { + "name": "draw", + "path": "folders/shader/draw.yy", + }, + "type": 1, +} \ No newline at end of file diff --git a/shaders/sh_draw_r8/sh_draw_r8.fsh b/shaders/sh_draw_r8/sh_draw_r8.fsh new file mode 100644 index 000000000..fced90f65 --- /dev/null +++ b/shaders/sh_draw_r8/sh_draw_r8.fsh @@ -0,0 +1,10 @@ +// +// Simple passthrough fragment shader +// +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() { + vec4 col = texture2D( gm_BaseTexture, v_vTexcoord ); + gl_FragColor = vec4(vec3(col.r), 1.); +} diff --git a/shaders/sh_draw_r8/sh_draw_r8.vsh b/shaders/sh_draw_r8/sh_draw_r8.vsh new file mode 100644 index 000000000..d4b316559 --- /dev/null +++ b/shaders/sh_draw_r8/sh_draw_r8.vsh @@ -0,0 +1,18 @@ +// +// Simple passthrough vertex shader +// +attribute vec3 in_Position; // (x,y,z) +//attribute vec3 in_Normal; // (x,y,z) unused in this shader. +attribute vec4 in_Colour; // (r,g,b,a) +attribute vec2 in_TextureCoord; // (u,v) + +varying vec2 v_vTexcoord; +varying vec4 v_vColour; + +void main() { + vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); + gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; + + v_vColour = in_Colour; + v_vTexcoord = in_TextureCoord; +} diff --git a/shaders/sh_draw_r8/sh_draw_r8.yy b/shaders/sh_draw_r8/sh_draw_r8.yy new file mode 100644 index 000000000..09a5efa06 --- /dev/null +++ b/shaders/sh_draw_r8/sh_draw_r8.yy @@ -0,0 +1,10 @@ +{ + "resourceType": "GMShader", + "resourceVersion": "1.0", + "name": "sh_draw_r8", + "parent": { + "name": "draw", + "path": "folders/shader/draw.yy", + }, + "type": 1, +} \ No newline at end of file