ShaderParticleInput.hx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package hrt.shgraph;
  2. using hxsl.Ast;
  3. @name("Particle Inputs")
  4. @description("Particle specific shader inputs")
  5. @group("Property")
  6. @color("#0e8826")
  7. class ShaderParticleInputs extends ShaderNode {
  8. @prop("Variable") public var variable : String = "life";
  9. public function new(variable = "life") {
  10. this.variable = variable;
  11. }
  12. override public function getAliases(name: String, group: String, description: String) {
  13. var aliases = super.getAliases(name, group, description);
  14. for (key => input in hrt.shgraph.ShaderParticleInputs.availableInputs) {
  15. aliases.push({
  16. nameSearch : name + " - " + input.display,
  17. group: group,
  18. description: description,
  19. args: [key],
  20. });
  21. }
  22. return aliases;
  23. }
  24. override function getOutputs() {
  25. static var outputs : Array<ShaderNode.OutputInfo> = [{name: "output", type: SgFloat(1)}];
  26. return outputs;
  27. }
  28. override function generate(ctx:NodeGenContext) {
  29. var global = availableInputs[variable].g;
  30. var expr = ctx.getGlobalInput(global);
  31. ctx.setOutput(0, expr);
  32. ctx.addPreview(expr);
  33. }
  34. override function loadProperties(props:Dynamic) {
  35. super.loadProperties(props);
  36. var ivar = availableInputs.get(this.variable);
  37. if (ivar == null) {
  38. for (k => v in availableInputs) {
  39. variable = k;
  40. break;
  41. }
  42. }
  43. }
  44. public static var availableInputs : Map<String, {display: String, g: Variables.Global}> = [
  45. "life" => {display: "Particle Life", g: ParticleLife},
  46. "lifetime" => {display: "Particle Life Time", g: ParticleLifeTime},
  47. "random" => {display: "Particle Random", g: ParticleRandom},
  48. ];
  49. #if editor
  50. override public function getPropertiesHTML(width : Float) : Array<hide.Element> {
  51. var elements = super.getPropertiesHTML(width);
  52. var element = new hide.Element('<div style="width: 120px; height: 30px"></div>');
  53. element.append(new hide.Element('<select id="variable"></select>'));
  54. if (variable == null) {
  55. variable = "position";
  56. }
  57. var input = element.children("select");
  58. var indexOption = 0;
  59. for (k => variable in availableInputs) {
  60. input.append(new hide.Element('<option value="${k}">${variable.display}</option>'));
  61. }
  62. input.val(variable);
  63. input.on("change", function(e) {
  64. variable = input.val();
  65. });
  66. elements.push(element);
  67. return elements;
  68. }
  69. #end
  70. }