hello_node.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 categories = nodes_material_categories;
  7. categories.push(category_name);
  8. // Create new node
  9. let nodes = [
  10. {
  11. id: 0,
  12. name: node_name,
  13. type: node_type,
  14. x: 0,
  15. y: 0,
  16. color: 0xffb34f5a,
  17. inputs: [
  18. {
  19. id: 0,
  20. node_id: 0,
  21. name: "Scale",
  22. type: "VALUE",
  23. color: 0xffa1a1a1,
  24. default_value: 1,
  25. min: 0.0,
  26. max: 5.0
  27. }
  28. ],
  29. outputs: [
  30. {
  31. id: 0,
  32. node_id: 0,
  33. name: "Color",
  34. type: "RGBA",
  35. color: 0xffc7c729,
  36. default_value: new Float32Array([0.8, 0.8, 0.8, 1.0])
  37. },
  38. {
  39. id: 1,
  40. node_id: 0,
  41. name: "Fac",
  42. type: "VALUE",
  43. color: 0xffa1a1a1,
  44. default_value: 1.0
  45. }
  46. ],
  47. buttons: []
  48. }
  49. ];
  50. nodes_material_list.push(nodes);
  51. // Node shader
  52. parser_material_custom_nodes.set(node_type, function(node, socket) {
  53. let frag = parser_material_frag;
  54. let scale = parser_material_parse_value_input(node.inputs[0]);
  55. let my_out = parser_material_node_name(node) + "_out";
  56. node_shader_write(frag,
  57. "float " + my_out + " = cos(sin(texCoord.x * 200.0 * " + scale + ") + cos(texCoord.y * 200.0 * " + scale + "));"
  58. );
  59. if (socket.name == "Color") {
  60. return "vec3(" + my_out + ", " + my_out + ", " + my_out + ")";
  61. }
  62. else if (socket.name == "Fac") {
  63. return my_out;
  64. }
  65. });
  66. // Cleanup
  67. plugin.delete = function() {
  68. parser_material_custom_nodes.delete(node_type);
  69. nodes_material_list.splice(nodes_material_list.indexOf(nodes), 1);
  70. categories.splice(categories.indexOf(category_name), 1);
  71. };