script_node.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function script_node_init() {
  2. array_push(nodes_material_input, script_node_def);
  3. map_set(parser_material_node_values, "SCRIPT_CPU", script_node_value);
  4. }
  5. function script_node_value(node: ui_node_t, socket: ui_node_socket_t): string {
  6. if (parser_material_script_links == null) {
  7. parser_material_script_links = map_create();
  8. }
  9. let script: buffer_t = node.buttons[0].default_value;
  10. let str: string = sys_buffer_to_string(script);
  11. let link: string = parser_material_node_name(node);
  12. map_set(parser_material_script_links, link, str);
  13. node_shader_add_constant(parser_material_kong, "" + link + ": float", "_" + link);
  14. return "constants." + link;
  15. }
  16. let script_node_def: ui_node_t = {
  17. id : 0,
  18. name : _tr("Script"),
  19. type : "SCRIPT_CPU", // extension
  20. x : 0,
  21. y : 0,
  22. color : 0xffb34f5a,
  23. inputs : [],
  24. outputs : [ {
  25. id : 0,
  26. node_id : 0,
  27. name : _tr("Value"),
  28. type : "VALUE",
  29. color : 0xffa1a1a1,
  30. default_value : f32_array_create_x(0.5),
  31. min : 0.0,
  32. max : 1.0,
  33. precision : 100,
  34. display : 0
  35. } ],
  36. buttons : [ {
  37. name : " ",
  38. type : "STRING",
  39. output : -1,
  40. default_value : f32_array_create_x(0), // "",
  41. data : null,
  42. min : 0.0,
  43. max : 1.0,
  44. precision : 100,
  45. height : 0
  46. } ],
  47. width : 0,
  48. flags : 0
  49. };