UI.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. "atomic component";
  2. "use strict";
  3. var __extends = (this && this.__extends) || function (d, b) {
  4. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  5. function __() { this.constructor = d; }
  6. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7. };
  8. /**
  9. * A new component
  10. */
  11. var UI = (function (_super) {
  12. __extends(UI, _super);
  13. function UI() {
  14. var _this = _super.apply(this, arguments) || this;
  15. /**
  16. * Fields witihin the inspectorFields object will be exposed to the editor
  17. */
  18. _this.inspectorFields = {};
  19. return _this;
  20. }
  21. /**
  22. * Called when the component is first added to the node
  23. */
  24. UI.prototype.start = function () {
  25. //creates a new scene, but doesn't load it to the player
  26. var scene = Atomic.player.loadScene("Scenes/Scene.scene");
  27. //get camera from the scene
  28. var camera = scene.getComponents("Camera", true)[0];
  29. //create a new UIView
  30. var view = new Atomic.UIView();
  31. // Create a UIWindow
  32. var window = new Atomic.UIWindow();
  33. // It will only have a title bar and won't be resizeable or have a close button
  34. window.settings = Atomic.UI_WINDOW_SETTINGS.UI_WINDOW_SETTINGS_TITLEBAR;
  35. window.text = "ShaderParameters";
  36. window.setSize(UI.WIDTH, UI.HEIGHT);
  37. var layout = new Atomic.UILayout();
  38. var slider = new Atomic.UISlider();
  39. slider.layoutWidth = 100;
  40. slider.setLimits(.1, 1.0);
  41. slider.value = 1;
  42. // The Scene View
  43. var sceneView = new Atomic.UISceneView();
  44. sceneView.setView(scene, camera);
  45. sceneView.autoUpdate = true;
  46. sceneView.layoutWidth = 512;
  47. sceneView.layoutHeight = 384;
  48. layout.addChild(sceneView);
  49. layout.addChild(slider);
  50. window.addChild(layout);
  51. // Add to main UI view and center
  52. view.addChild(window);
  53. window.center();
  54. var viewport = sceneView.viewport;
  55. var renderPath = viewport.renderPath;
  56. // Add a blur post process effect
  57. viewport.renderPath.append(Atomic.cache.getResource("XMLFile", "PostProcess/MyBlur.xml"));
  58. // Get the individual blur commands from MyBlur.xml
  59. var rpc = new Atomic.RenderPathCommand();
  60. var commands = [];
  61. for (var i = 0; i < renderPath.numCommands; i++) {
  62. renderPath.getCommand(i, rpc);
  63. if (rpc.tag == "Blur1" || rpc.tag == "Blur2" ||
  64. rpc.tag == "Blur3" || rpc.tag == "Blur4") {
  65. // store off the command index so we can update it later
  66. rpc["cmdIndex"] = i;
  67. commands.push(rpc);
  68. rpc = new Atomic.RenderPathCommand();
  69. }
  70. }
  71. this.subscribeToEvent(slider, Atomic.UIWidgetEvent(function (ev) {
  72. if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_CHANGED) {
  73. var value = 2.0 * slider.value;
  74. // This works, can set globally
  75. //renderPath.setShaderParameter("BlurSigma", value);
  76. // Though, for this example set per command
  77. for (var i = 0; i < commands.length; i++) {
  78. var cmd = commands[i];
  79. cmd.setShaderParameter("BlurSigma", value);
  80. // update in the renderPath
  81. renderPath.setCommand(cmd["cmdIndex"], cmd);
  82. }
  83. }
  84. }));
  85. };
  86. /**
  87. * Update called every cycle with timeStep containing the delta between calls
  88. * @param timeStep time since last call to update
  89. */
  90. UI.prototype.update = function (timeStep) {
  91. };
  92. return UI;
  93. }(Atomic.JSComponent));
  94. UI.WIDTH = 640;
  95. UI.HEIGHT = 480;
  96. Object.defineProperty(exports, "__esModule", { value: true });
  97. exports.default = UI;