aentity.js 4.7 KB

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