ascene.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. this.initialize = function () {
  2. this.future(0).clientWatch();
  3. };
  4. this.clientWatch = function () {
  5. var self = this;
  6. if (this.children.length !== 0) {
  7. var clients = this.find("doc('http://vwf.example.com/clients.vwf')")[0];
  8. if (clients !== undefined) {
  9. //console.log(clients.children);
  10. let clientsArray = [];
  11. clients.children.forEach(function (element) {
  12. clientsArray.push(element.name);
  13. });
  14. this.children.forEach(function (node) {
  15. if (node.id.indexOf('avatar-') != -1) {
  16. if (clientsArray.includes(node.id.slice(7))) {
  17. //console.log(node.id + 'is here!');
  18. } else {
  19. //console.log(node.id + " needed to delete!");
  20. self.children.delete(self.children[node.id]);
  21. //'gearvr-'
  22. let controllerVR = self.children['gearvr-' + node.id.slice(7)];
  23. if (controllerVR) {
  24. self.children.delete(controllerVR);
  25. }
  26. let wmrvR = self.children['wmrvr-right-' + node.id.slice(7)];
  27. if (wmrvR) {
  28. self.children.delete(wmrvR);
  29. }
  30. let wmrvL = self.children['wmrvr-left-' + node.id.slice(7)];
  31. if (wmrvL) {
  32. self.children.delete(wmrvL);
  33. }
  34. }
  35. }
  36. });
  37. }
  38. }
  39. this.future(5).clientWatch();
  40. };
  41. this.sphereProto = function () {
  42. let node = {
  43. "extends": "http://vwf.example.com/aframe/asphere.vwf",
  44. "properties": {
  45. "displayName": "sphere",
  46. "color": "white",
  47. "radius": 1,
  48. "clickable": true
  49. },
  50. children: {
  51. "interpolation":
  52. {
  53. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  54. "type": "component",
  55. "properties": {
  56. "enabled": true
  57. }
  58. },
  59. "cursor-listener": {
  60. "extends": "http://vwf.example.com/aframe/app-cursor-listener-component.vwf",
  61. "type": "component"
  62. }
  63. },
  64. events: {
  65. "clickEvent": {
  66. "body": ""
  67. }
  68. }
  69. }
  70. return node
  71. }
  72. this.cubeProto = function () {
  73. let node = {
  74. "extends": "http://vwf.example.com/aframe/abox.vwf",
  75. "properties": {
  76. "displayName": "cube",
  77. "color": "white",
  78. "height": 1,
  79. "width": 1,
  80. "depth": 1,
  81. "clickable": true
  82. },
  83. children: {
  84. "interpolation":
  85. {
  86. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  87. "type": "component",
  88. "properties": {
  89. "enabled": true
  90. }
  91. },
  92. "cursor-listener": {
  93. "extends": "http://vwf.example.com/aframe/app-cursor-listener-component.vwf",
  94. "type": "component"
  95. }
  96. },
  97. events: {
  98. "clickEvent": {
  99. "body": ""
  100. }
  101. }
  102. }
  103. return node
  104. }
  105. this.createPrimitive = function (type, avatar, name, node) {
  106. var position = "0 0 0";
  107. var nodeName = name;
  108. let myAvatar = this.children[avatar];
  109. let cursorNode = myAvatar.avatarNode.myHead.myCursor.vis;
  110. if (cursorNode) {
  111. position = cursorNode.worldPosition;
  112. //console.log(position);
  113. }
  114. if (!name) {
  115. nodeName = this.GUID();
  116. }
  117. var newNode = {};
  118. switch (type) {
  119. case "cube":
  120. newNode = this.cubeProto();
  121. break;
  122. case "sphere":
  123. newNode = this.sphereProto();
  124. break;
  125. default:
  126. newNode = undefined;
  127. break;
  128. }
  129. if (newNode) {
  130. newNode.properties.position = position;
  131. this.children.create(nodeName, newNode);
  132. }
  133. }
  134. this.GUID = function () {
  135. var self = this;
  136. var S4 = function () {
  137. return Math.floor(
  138. self.random() * 0x10000 /* 65536 */
  139. ).toString(16);
  140. };
  141. return (
  142. S4() + S4() + "-" +
  143. S4() + "-" +
  144. S4() + "-" +
  145. S4() + "-" +
  146. S4() + S4() + S4()
  147. );
  148. }
  149. this.smallRandomId = function() {
  150. return '_' + this.random().toString(36).substr(2, 9);
  151. }
  152. this.assetImgProto = function () {
  153. let node = {
  154. "extends": "http://vwf.example.com/aframe/a-asset-image-item.vwf",
  155. "properties": {
  156. },
  157. }
  158. return node
  159. }
  160. this.createAssetItemImg = function(){
  161. console.log("create new asset item for img");
  162. let nodeName = "asset-item-img-" + this.smallRandomId();
  163. let newNode = {
  164. "extends": "http://vwf.example.com/aframe/a-asset-image-item.vwf",
  165. "properties": {
  166. itemID: nodeName,
  167. itemSrc: ""
  168. }
  169. }
  170. this.children.create(nodeName, newNode);
  171. }