transport.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. this.initialize = function () {
  2. //this.createTransportVis();
  3. }
  4. this.simpleVis = function () {
  5. return {
  6. "extends": "proxy/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": "proxy/aframe/aMaterialComponent.vwf",
  16. "type": "component",
  17. "properties": {
  18. "color": "red"
  19. }
  20. },
  21. "cursor-listener": {
  22. extends: "proxy/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.animationTPS = 30;
  43. //this.animationPlay(0,1);
  44. }
  45. this.animationUpdate = function (time, duration) {
  46. //let sceneID = this.find("/")[0].id
  47. let rate = this.animationTPS / this.animationRate; // 60/1 by default
  48. var b = this.beat;
  49. //console.log('b: ' + this.beat + ' t: ' + time + ' ta: ' + this.time);
  50. if (time == this.animationDuration) { //time == 1 &&
  51. this.beat = 0;
  52. //this.doGlobalBeat(time, duration, b);
  53. } else {
  54. this.doGlobalBeat(time, duration, b);
  55. this.beat = this.beat + 1;
  56. }
  57. }
  58. this.doGlobalBeat = function (time, duration, beat) {
  59. let allChilds = this.find("//element(*,'proxy/aframe/aentity.vwf')"); //this.children
  60. allChilds.forEach(el => {
  61. if (el.globalBeat) {
  62. let obj = {
  63. name: this.name,
  64. time: time,
  65. duration: duration,
  66. beat: beat
  67. }
  68. el.onGlobalBeat(obj);
  69. }
  70. })
  71. }
  72. this.init = function () {
  73. this.children.create("vis", this.simpleVis(), function (child) {
  74. child.clickEventMethod = function () {
  75. if (this.parent.animationPlaying) {
  76. this.parent.stop();
  77. } else {
  78. this.parent.play();
  79. }
  80. }
  81. });
  82. this.setupTransport();
  83. //this.play();
  84. }