ascene.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.createCube = function(name, avatar, node){
  42. let myAvatar = this.children[avatar];
  43. let cursorNode = myAvatar.avatarNode.myHead.myCursor.vis;
  44. var position = "0 0 0";
  45. if (cursorNode){
  46. position = cursorNode.worldPosition;
  47. //console.log(position);
  48. }
  49. let cube = {
  50. "extends": "http://vwf.example.com/aframe/abox.vwf",
  51. "properties": {
  52. "displayName": "cube",
  53. "color": "white",
  54. "height": 1,
  55. "width": 1,
  56. "depth": 1,
  57. "position": position
  58. },
  59. children: {
  60. "interpolation":
  61. {
  62. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  63. "type": "component",
  64. "properties": {
  65. "enabled": true
  66. }
  67. }
  68. }
  69. }
  70. this.children.create(name, cube);
  71. }