2
0

hello_node.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: "Factor",
  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. flags: 0
  57. }
  58. ];
  59. nodes_material_category_add(category_name, armpack_encode(node_list));
  60. // Node shader
  61. parser_material_custom_nodes_set(node_type, function(node, socket_name) {
  62. let kong = parser_material_kong_get();
  63. let scale = parser_material_parse_value_input(node, 0);
  64. let my_out = "my_out";
  65. node_shader_write_frag(kong,
  66. "var " + my_out + ": float = cos(sin(tex_coord.x * 200.0 * " + scale + ") + cos(tex_coord.y * 200.0 * " + scale + "));"
  67. );
  68. if (socket_name == "Color") {
  69. return "float3(" + my_out + ", " + my_out + ", " + my_out + ")";
  70. }
  71. else if (socket_name == "Factor") {
  72. return my_out;
  73. }
  74. });
  75. // Cleanup
  76. plugin_notify_on_delete(plugin, function() {
  77. parser_material_custom_nodes_delete(node_type);
  78. nodes_material_category_remove(category_name);
  79. });