aentity.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. this.getChildByName = function (name) {
  2. let nodes = this.children.filter(el => el.displayName == name);
  3. return nodes[0]
  4. }
  5. this.setGizmoMode = function (mode) {
  6. if (this.gizmo) {
  7. this.gizmo.properties.mode = mode
  8. }
  9. }
  10. this.showCloseGizmo = function () {
  11. let gizmoNode =
  12. {
  13. "extends": "http://vwf.example.com/aframe/gizmoComponent.vwf",
  14. "type": "component",
  15. "properties":
  16. {
  17. "mode": "translate"
  18. }
  19. }
  20. if (this.properties.edit) {
  21. this.children.create("gizmo", gizmoNode);
  22. } else {
  23. if (this.gizmo) {
  24. this.children.delete(this.gizmo)
  25. }
  26. }
  27. }
  28. // Parse a parameter as a translation specification.
  29. this.translationFromValue = function (propertyValue) {
  30. var value = goog.vec.Vec3.create();
  31. if (propertyValue.hasOwnProperty('x')) {
  32. value = goog.vec.Vec3.createFromValues(propertyValue.x, propertyValue.y, propertyValue.z)
  33. }
  34. else if (Array.isArray(propertyValue) || propertyValue instanceof Float32Array) {
  35. value = goog.vec.Vec3.createFromArray(propertyValue);
  36. }
  37. else if (typeof propertyValue === 'string') {
  38. let val = AFRAME.utils.coordinates.parse(propertyValue);
  39. value = goog.vec.Vec3.createFromValues(val.x, val.y, val.z)
  40. }
  41. return value
  42. // return value && value.length >= 3 ?
  43. // value :
  44. // goog.vec.Vec3.create();
  45. };
  46. this.sendOSC = function (msg) {
  47. //sending OSC msg
  48. vwf_view.kernel.fireEvent(this.id, "sendOSC", [msg]);
  49. // if (_OSCManager.port !== null) {
  50. // _OSCManager.port.send(msg);
  51. // }
  52. //on driver side
  53. }
  54. // this.clickEvent = function () {
  55. // //this.intersectEventMethod();
  56. // }
  57. // this.intersectEvent = function () {
  58. // //this.intersectEventMethod();
  59. // }
  60. // this.clearIntersectEvent = function () {
  61. // //this.clearIntersectEventMethod();
  62. // }
  63. this.intersectEventMethod = function () {
  64. //intersect method
  65. }
  66. this.clearIntersectEventMethod = function () {
  67. //clearIntersect method
  68. }
  69. this.hitstartEventMethod = function () {
  70. //intersect method
  71. }
  72. this.hitendEventMethod = function () {
  73. //clearIntersect method
  74. }
  75. this.clickEventMethod = function () {
  76. //clickEventMethod
  77. }
  78. this.setOwner = function (param) {
  79. var clients = this.find("doc('http://vwf.example.com/clients.vwf')")[0];
  80. if (clients !== undefined) {
  81. //console.log(clients.children);
  82. let clientsArray = [];
  83. clients.children.forEach(function (element) {
  84. clientsArray.push(element.name);
  85. });
  86. //console.log(clientsArray);
  87. if (this.ownedBy) {
  88. if (clientsArray.includes(this.ownedBy)) {
  89. console.log(this.id + " already owned by: " + param);
  90. } else {
  91. this.ownedBy = param;
  92. //console.log(this.id + ' set owner to: ' + param);
  93. }
  94. } else {
  95. this.ownedBy = param;
  96. //console.log(this.id + ' set owner to: ' + param);
  97. }
  98. }
  99. }
  100. this.updateMethod = function (methodName, methodBody, params) {
  101. vwf_view.kernel.setMethod(this.id, methodName, { body: methodBody, type: "application/javascript", parameters: params});
  102. }
  103. this.callMethod = function(methodName, params){
  104. vwf_view.kernel.callMethod(this.id, methodName, params)
  105. }
  106. this.step = function(){
  107. if (this.stepping){
  108. this.do();
  109. }
  110. let t = this.stepTime ? this.stepTime: 0.05;
  111. this.future(t).step();
  112. }
  113. this.onGlobalBeat = function(obj) {
  114. //dispatch the beat example send OSC
  115. let transportNode = this.find('//' + obj.name)[0];
  116. let rate = transportNode.animationRate; // 1 by default
  117. let drumSeq = [
  118. {beat:0, msg: 0},
  119. {beat:30, msg: 0}];
  120. drumSeq.forEach(el=>{
  121. if(el.beat/rate == obj.beat){
  122. let msg = {
  123. address: "/trigger/sample01",
  124. args: [this.time, 'bd_808', 3]
  125. };
  126. //for synth {beat:0, msg: "A"}
  127. //let msg = {
  128. // address: "/trigger/synth01",
  129. // args: [this.time, 'piano', el.msg, 0.1, 1]};
  130. // this.sendOSC(msg);
  131. // this.changeVisual();
  132. }
  133. })
  134. }
  135. this.changeVisual = function() {
  136. //code for changing me
  137. this.future(0.1).resetVisual();
  138. }
  139. this.resetVisual = function() {
  140. }