flir.nas 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # flir camera control
  2. # 12/2017 by G-EED
  3. var sar_selected = 0;
  4. var nodeFlir=nil;
  5. var numWeight=0;
  6. var options = std.Vector.new();
  7. var numView = 0;
  8. stringContainWords = func(s,words){
  9. var found = 0;
  10. foreach(var w; words.vector) {
  11. if( string.match(s,w) ){
  12. found=1;
  13. break;
  14. }
  15. }
  16. return found;
  17. }
  18. activate_flir_shader = func(a){
  19. if(getprop("sim/rendering/rembrandt/enabled")==0){
  20. setprop("sim/rendering/als-filters/use-filtering", a);
  21. setprop("sim/rendering/als-filters/use-IR-vision", a);
  22. }else{
  23. setprop("sim/rendering/rembrandt/night-vision", a);
  24. }
  25. }
  26. check_view_for_flir = func(n){
  27. print("check_view_for_flir",n,"");
  28. var viewnum = 0;
  29. foreach(var w; props.globals.getNode("sim").getChildren("view")) {
  30. if(n==viewnum){
  31. var selected = w.getNode("flir");
  32. if(selected != nil) {
  33. print("view ",viewnum," has a FLIR");
  34. activate_flir_shader(1);
  35. }else{
  36. print("view ",viewnum," has no FLIR");
  37. activate_flir_shader(0);
  38. }
  39. }
  40. viewnum=viewnum+1;
  41. }
  42. }
  43. setlistener("sim/signals/fdm-initialized", func {
  44. nodeFlir = props.globals.getNode("sim/flir");
  45. if(nodeFlir != nil){
  46. numWeight = nodeFlir.getValue("weight");
  47. if(numWeight!=nil){
  48. numView = nodeFlir.getValue("view");
  49. if(numWeight!=nil){
  50. foreach(var w; nodeFlir.getNode("options").getChildren("name")) {
  51. options.append(w.getValue());
  52. }
  53. if(options.size() > 0){
  54. setlistener("sim/weight["~numWeight~"]/selected", func(s) {
  55. if( stringContainWords( getprop("sim/weight["~numWeight~"]/selected") , options ) == 1 ){
  56. print("SAR selected");
  57. setprop("sim/view["~numView~"]/enabled",1);
  58. #activate_flir_shader(1);
  59. }else{
  60. print("SAR deselected");
  61. setprop("sim/view["~numView~"]/enabled",0);
  62. #activate_flir_shader(0);
  63. }
  64. }, 1);
  65. setlistener("/sim/current-view/view-number", func(n) {
  66. check_view_for_flir(n.getValue());
  67. }, 1);
  68. print("Flir: SUCCESS! view control ......... Initialized");
  69. }else{
  70. print("Flir: FAILED! Error: No options have been defined for the weight",numWeight);
  71. }
  72. }else{
  73. print("Flir: FAILED! Error: No FLIR view has been defined");
  74. }
  75. }else{
  76. print("Flir: FAILED! Error: Could not find property node sim/flir/_attr_/weight");
  77. }
  78. }else{
  79. print("Flir: FAILED! Error: Could not find property node sim/flir");
  80. }
  81. });