ShaderInput.hx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package hrt.shgraph;
  2. using hxsl.Ast;
  3. @name("Inputs")
  4. @description("Shader inputs of Heaps, it's dynamic")
  5. @group("Property")
  6. @color("#0e8826")
  7. class ShaderInput extends ShaderNode {
  8. @output() var output = SType.Variant;
  9. @prop("Variable") public var variable : TVar;
  10. override public function getOutput(key : String) : TVar {
  11. return variable;
  12. }
  13. override public function build(key : String) : TExpr {
  14. return null;
  15. }
  16. public static var availableInputs : Array<TVar> = [
  17. { parent: null, id: 0, kind: Input, name: "position", type: TVec(3, VFloat) },
  18. { parent: null, id: 0, kind: Input, name: "color", type: TVec(3, VFloat) },
  19. { parent: null, id: 0, kind: Input, name: "uv", type: TVec(2, VFloat) },
  20. { parent: null, id: 0, kind: Input, name: "normal", type: TVec(3, VFloat) },
  21. { parent: null, id: 0, kind: Input, name: "tangent", type: TVec(3, VFloat) },
  22. { parent: null, id: 0, kind: Local, name: "relativePosition", type: TVec(3, VFloat) },
  23. { parent: null, id: 0, kind: Local, name: "transformedPosition", type: TVec(3, VFloat) },
  24. { parent: null, id: 0, kind: Local, name: "projectedPosition", type: TVec(4, VFloat) },
  25. { parent: null, id: 0, kind: Local, name: "transformedNormal", type: TVec(3, VFloat) },
  26. { parent: null, id: 0, kind: Local, name: "screenUV", type: TVec(2, VFloat) },
  27. { parent: null, id: 0, kind: Local, name: "calculatedUV", type: TVec(2, VFloat) },
  28. ];
  29. override public function loadProperties(props : Dynamic) {
  30. var paramVariable : String = Reflect.field(props, "variable");
  31. for (c in ShaderNode.availableVariables) {
  32. if (c.name == paramVariable) {
  33. this.variable = c;
  34. return;
  35. }
  36. }
  37. for (c in ShaderInput.availableInputs) {
  38. if (c.name == paramVariable) {
  39. this.variable = c;
  40. return;
  41. }
  42. }
  43. }
  44. override public function saveProperties() : Dynamic {
  45. var parameters = {
  46. variable: (variable == null) ? null : variable.name
  47. };
  48. return parameters;
  49. }
  50. #if editor
  51. override public function getPropertiesHTML(width : Float) : Array<hide.Element> {
  52. var elements = super.getPropertiesHTML(width);
  53. var element = new hide.Element('<div style="width: 120px; height: 30px"></div>');
  54. element.append(new hide.Element('<select id="variable"></select>'));
  55. if (this.variable == null) {
  56. this.variable = ShaderNode.availableVariables[0];
  57. }
  58. var input = element.children("select");
  59. var indexOption = 0;
  60. for (c in ShaderNode.availableVariables) {
  61. var nameSplitted = c.name.split(".");
  62. input.append(new hide.Element('<option value="${indexOption}">${nameSplitted[nameSplitted.length-1]}</option>'));
  63. if (this.variable.name == c.name) {
  64. input.val(indexOption);
  65. }
  66. indexOption++;
  67. }
  68. for (c in ShaderInput.availableInputs) {
  69. input.append(new hide.Element('<option value="${indexOption}">${c.name}</option>'));
  70. if (this.variable.name == c.name) {
  71. input.val(indexOption);
  72. }
  73. indexOption++;
  74. }
  75. input.on("change", function(e) {
  76. var value = input.val();
  77. if (value < ShaderNode.availableVariables.length) {
  78. this.variable = ShaderNode.availableVariables[value];
  79. } else {
  80. this.variable = ShaderInput.availableInputs[value-ShaderNode.availableVariables.length];
  81. }
  82. });
  83. elements.push(element);
  84. return elements;
  85. }
  86. #end
  87. }