ShaderGlobalInput.hx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package hrt.shgraph;
  2. using hxsl.Ast;
  3. @name("Global")
  4. @description("Global Inputs")
  5. @group("Property")
  6. @color("#0e8826")
  7. class ShaderGlobalInput extends ShaderInput {
  8. static public var globalInputs = [ { parent: null, id: 0, kind: Global, name: "global.time", type: TFloat },
  9. { parent: null, id: 0, kind: Global, name: "global.pixelSize", type: TVec(2, VFloat) },
  10. { parent: null, id: 0, kind: Global, name: "global.modelView", type: TMat4 },
  11. { parent: null, id: 0, kind: Global, name: "global.modelViewInverse", type: TMat4 } ];
  12. override public function loadProperties(props : Dynamic) {
  13. var paramVariable : String = Reflect.field(props, "variable");
  14. for (c in ShaderGlobalInput.globalInputs) {
  15. if (c.name == paramVariable) {
  16. this.variable = c;
  17. return;
  18. }
  19. }
  20. }
  21. #if editor
  22. override public function getPropertiesHTML(width : Float) : Array<hide.Element> {
  23. var elements = [];
  24. var element = new hide.Element('<div style="width: 120px; height: 30px"></div>');
  25. element.append(new hide.Element('<select id="variable"></select>'));
  26. if (this.variable == null)
  27. this.variable = ShaderGlobalInput.globalInputs[0];
  28. var input = element.children("select");
  29. var indexOption = 0;
  30. for (c in ShaderGlobalInput.globalInputs) {
  31. var name = c.name.split(".")[1];
  32. input.append(new hide.Element('<option value="${indexOption}">${name}</option>'));
  33. if (this.variable.name == c.name) {
  34. input.val(indexOption);
  35. }
  36. indexOption++;
  37. }
  38. input.on("change", function(e) {
  39. var value = input.val();
  40. this.variable = ShaderGlobalInput.globalInputs[value];
  41. });
  42. elements.push(element);
  43. return elements;
  44. }
  45. #end
  46. }