aentity.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.do = function() {
  107. //do in step
  108. }
  109. this.step = function(){
  110. if (this.stepping){
  111. this.do();
  112. }
  113. let t = this.stepTime ? this.stepTime: 0.05;
  114. this.future(t).step();
  115. }
  116. this.onGlobalBeat = function(obj) {
  117. //dispatch the beat example send OSC
  118. let transportNode = this.find('//' + obj.name)[0];
  119. let rate = transportNode.animationRate; // 1 by default
  120. let drumSeq = [
  121. {beat:0, msg: 0},
  122. {beat:30, msg: 0}];
  123. drumSeq.forEach(el=>{
  124. if(el.beat/rate == obj.beat){
  125. let msg = {
  126. address: "/trigger/sample01",
  127. args: [this.time, 'bd_808', 3]
  128. };
  129. //for synth {beat:0, msg: "A"}
  130. //let msg = {
  131. // address: "/trigger/synth01",
  132. // args: [this.time, 'piano', el.msg, 0.1, 1]};
  133. // this.sendOSC(msg);
  134. // this.changeVisual();
  135. }
  136. })
  137. }
  138. this.changeVisual = function() {
  139. //code for changing me
  140. this.future(0.1).resetVisual();
  141. }
  142. this.resetVisual = function() {
  143. }