ShaderCameraInput.hx 2.2 KB

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