transport.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. this.initialize = function () {
  2. //this.createTransportVis();
  3. }
  4. this.simpleVis = function () {
  5. return {
  6. "extends": "http://vwf.example.com/aframe/abox.vwf",
  7. "properties": {
  8. "height": 0.3,
  9. "width": 0.3,
  10. "depth": 0.3,
  11. "class": "clickable"
  12. },
  13. "children": {
  14. "material": {
  15. "extends": "http://vwf.example.com/aframe/aMaterialComponent.vwf",
  16. "type": "component",
  17. "properties": {
  18. "color": "red"
  19. }
  20. },
  21. "cursor-listener": {
  22. extends: "http://vwf.example.com/aframe/app-cursor-listener-component.vwf",
  23. type: "component"
  24. }
  25. }
  26. }
  27. }
  28. this.stop = function () {
  29. this.animationStop();
  30. this.playing = false;
  31. }
  32. this.play = function () {
  33. this.beat = 0;
  34. this.animationPlay(0, this.animationDuration);
  35. this.playing = true;
  36. }
  37. this.setupTransport = function () {
  38. this.beat = 0;
  39. this.animationLoop = true;
  40. this.animationDuration = 1;
  41. this.animationRate = 1;
  42. //this.animationPlay(0,1);
  43. }
  44. this.animationUpdate = function (time, duration) {
  45. //let sceneID = this.find("/")[0].id
  46. let rate = this.animationTPS / this.animationRate; // 60/1 by default
  47. var b = this.beat;
  48. //console.log('time: ' + time + ' b: ' + this.beat + ' simTime: ' + this.time);
  49. if (b == rate + 1) { //time == 1 &&
  50. this.beat = 0;
  51. }
  52. else {
  53. this.doGlobalBeat(time, duration, b);
  54. //vwf_view.kernel.fireEvent(this.id, "transportTick", [time, duration, this.beat]);
  55. if (b / rate == 0) {
  56. this.vis.material.color = "white";
  57. } else if (b / rate == 1 / 2) {
  58. this.vis.material.color = "red";
  59. }
  60. this.beat = this.beat + 1;
  61. }
  62. }
  63. this.doGlobalBeat = function (time, duration, beat) {
  64. let allChilds = this.find("//element(*,'http://vwf.example.com/aframe/aentity.vwf')");
  65. allChilds.forEach(el => {
  66. if (el.globalBeat) {
  67. let obj = {
  68. name: this.name,
  69. time: time,
  70. duration: duration,
  71. beat: beat
  72. }
  73. el.onGlobalBeat(obj);
  74. }
  75. })
  76. }
  77. this.init = function () {
  78. this.children.create("vis", this.simpleVis(), function (child) {
  79. child.clickEventMethod = function () {
  80. if (this.parent.animationPlaying) {
  81. this.parent.stop();
  82. } else {
  83. this.parent.play();
  84. }
  85. }
  86. });
  87. this.setupTransport();
  88. //this.play();
  89. }