hello_node.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. let plugin = plugin_create();
  2. let category_name = "My Nodes";
  3. let node_name = "Hello World";
  4. let node_type = "HELLO_WORLD";
  5. // Create new node category
  6. let node_list = [
  7. {
  8. id: 0,
  9. name: node_name,
  10. type: node_type,
  11. x: 0,
  12. y: 0,
  13. color: 0xffb34f5a,
  14. inputs: [
  15. {
  16. id: 0,
  17. node_id: 0,
  18. name: "Scale",
  19. type: "VALUE",
  20. color: 0xffa1a1a1,
  21. default_value__f32: [1.0],
  22. min__f32: 0.0,
  23. max__f32: 5.0,
  24. precision__f32: 100.0,
  25. display: 0
  26. }
  27. ],
  28. outputs: [
  29. {
  30. id: 0,
  31. node_id: 0,
  32. name: "Color",
  33. type: "RGBA",
  34. color: 0xffc7c729,
  35. default_value__f32: [0.8, 0.8, 0.8, 1.0],
  36. min__f32: 0.0,
  37. max__f32: 1.0,
  38. precision__f32: 100.0,
  39. display: 0
  40. },
  41. {
  42. id: 1,
  43. node_id: 0,
  44. name: "Fac",
  45. type: "VALUE",
  46. color: 0xffa1a1a1,
  47. default_value__f32: [1.0],
  48. min__f32: 0.0,
  49. max__f32: 1.0,
  50. precision__f32: 100.0,
  51. display: 0
  52. }
  53. ],
  54. buttons: [],
  55. width: 0
  56. }
  57. ];
  58. nodes_material_category_add(category_name, armpack_encode(node_list));
  59. // Node shader
  60. parser_material_custom_nodes_set(node_type, function(node, socket_name) {
  61. let kong = parser_material_kong_get();
  62. let scale = parser_material_parse_value_input(node, 0);
  63. let my_out = "my_out";
  64. node_shader_write_frag(kong,
  65. "var " + my_out + ": float = cos(sin(tex_coord.x * 200.0 * " + scale + ") + cos(tex_coord.y * 200.0 * " + scale + "));"
  66. );
  67. if (socket_name == "Color") {
  68. return "float3(" + my_out + ", " + my_out + ", " + my_out + ")";
  69. }
  70. else if (socket_name == "Fac") {
  71. return my_out;
  72. }
  73. });
  74. // Cleanup
  75. plugin_notify_on_delete(plugin, function() {
  76. parser_material_custom_nodes_delete(node_type);
  77. nodes_material_category_remove(category_name);
  78. });