hello_node.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. let plugin = new arm.Plugin();
  2. let categoryName = "My Nodes";
  3. let nodeName = "Hello World";
  4. let nodeType = "HELLO_WORLD";
  5. // Create new node category
  6. let categories = arm.NodesMaterial.categories;
  7. categories.push(categoryName);
  8. // Create new node
  9. let nodes = [
  10. {
  11. id: 0,
  12. name: nodeName,
  13. type: nodeType,
  14. x: 0,
  15. y: 0,
  16. color: 0xffb34f5a,
  17. inputs: [],
  18. outputs: [
  19. {
  20. id: 0,
  21. node_id: 0,
  22. name: "Color",
  23. type: "RGBA",
  24. color: 0xffc7c729,
  25. default_value: [0.8, 0.8, 0.8, 1.0]
  26. }
  27. ],
  28. buttons: []
  29. }
  30. ];
  31. arm.NodesMaterial.list.push(nodes);
  32. // Node shader
  33. arm.Material.customNodes.set(nodeType, function() {
  34. let frag = arm.Material.frag;
  35. frag.write(`
  36. float my_out = cos(sin(texCoord.x * 200) + cos(texCoord.y * 200));
  37. `);
  38. return `vec3(my_out, my_out, my_out)`;
  39. });
  40. // Cleanup
  41. plugin.delete = function() {
  42. arm.Material.customNodes.delete(nodeType);
  43. arm.NodesMaterial.list.splice(arm.NodesMaterial.list.indexOf(nodes), 1);
  44. categories.splice(categories.indexOf(categoryName), 1);
  45. };