ascene.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. },
  49. children: {
  50. "interpolation":
  51. {
  52. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  53. "type": "component",
  54. "properties": {
  55. "enabled": true
  56. }
  57. }
  58. }
  59. }
  60. return node
  61. }
  62. this.cubeProto = function(){
  63. let node = {
  64. "extends": "http://vwf.example.com/aframe/abox.vwf",
  65. "properties": {
  66. "displayName": "cube",
  67. "color": "white",
  68. "height": 1,
  69. "width": 1,
  70. "depth": 1
  71. },
  72. children: {
  73. "interpolation":
  74. {
  75. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  76. "type": "component",
  77. "properties": {
  78. "enabled": true
  79. }
  80. }
  81. }
  82. }
  83. return node
  84. }
  85. this.createPrimitive = function(type, avatar, name, node){
  86. var position = "0 0 0";
  87. var nodeName = name;
  88. let myAvatar = this.children[avatar];
  89. let cursorNode = myAvatar.avatarNode.myHead.myCursor.vis;
  90. if (cursorNode){
  91. position = cursorNode.worldPosition;
  92. //console.log(position);
  93. }
  94. if (!name) {
  95. nodeName = this.GUID();
  96. }
  97. var newNode = {};
  98. switch (type) {
  99. case "cube":
  100. newNode = this.cubeProto();
  101. break;
  102. case "sphere":
  103. newNode = this.sphereProto();
  104. break;
  105. default:
  106. newNode = undefined;
  107. break;
  108. }
  109. if (newNode) {
  110. newNode.properties.position = position;
  111. this.children.create(nodeName, newNode);
  112. }
  113. }
  114. this.GUID = function () {
  115. var self = this;
  116. var S4 = function () {
  117. return Math.floor(
  118. self.random() * 0x10000 /* 65536 */
  119. ).toString(16);
  120. };
  121. return (
  122. S4() + S4() + "-" +
  123. S4() + "-" +
  124. S4() + "-" +
  125. S4() + "-" +
  126. S4() + S4() + S4()
  127. );
  128. }