aentity.js 5.0 KB

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