aframe-ar-driver.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
  4. Virtual World Framework Apache 2.0 license (https://github.com/NikolaySuslov/livecodingspace/blob/master/licenses/LICENSE_VWF.md)
  5. */
  6. // VWF & OSC driver
  7. import {Fabric} from '/core/vwf/fabric.js';
  8. class AFrameARView extends Fabric {
  9. constructor(module) {
  10. console.log("AFrameARView constructor");
  11. super(module, 'View');
  12. }
  13. factory() {
  14. let _self_ = this;
  15. return this.load(this.module,
  16. {
  17. initialize: function() {
  18. let self = this;
  19. this.fabric = _self_;
  20. },
  21. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  22. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  23. // var node = this.state.nodes[childID];
  24. // // If the "nodes" object does not have this object in it, it must not be one that
  25. // // this driver cares about
  26. // if (!node) {
  27. // return;
  28. // }
  29. },
  30. initializedNode: function (nodeID, childID) {
  31. let self = this;
  32. //let viewDriver = vwf.views["vwf/view/aframe"];
  33. let viewDriver = vwf.views["/drivers/view/aframe"];
  34. if (!viewDriver) {
  35. return;
  36. }
  37. let node = viewDriver.state.nodes[childID];
  38. if (!node) {
  39. return;
  40. }
  41. if (viewDriver.state.scenes[childID]) {
  42. let scene = viewDriver.state.scenes[childID];
  43. scene.setAttribute('embedded', {});
  44. scene.setAttribute('arjs', {trackingMethod: "best", sourceType: "webcam", debugUIEnabled: "false"});
  45. }
  46. if (viewDriver.state.nodes[childID].extendsID == "proxy/aframe/acamera.vwf") {
  47. //if(!childID.includes('avatar')){
  48. if(node.type == 'ar'){
  49. console.log(childID);
  50. vwf_view.kernel.callMethod(childID, "setCameraToActive", [vwf.moniker_]);
  51. }
  52. }
  53. },
  54. firedEvent: function (nodeID, eventName, eventParameters) {
  55. // var node = self.viewDriver.state.nodes[nodeID];
  56. // if (!node) {
  57. // return;
  58. // }
  59. // if (eventName == "createAvatar") {
  60. // let avatarName = 'avatar-' + self.kernel.moniker();
  61. // vwf_view.kernel.callMethod(avatarName, "showHideAvatar", false);
  62. // }
  63. },
  64. /*
  65. * Receives incoming messages
  66. */
  67. calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  68. let self = this;
  69. let viewDriver = vwf.views["/drivers/view/aframe"];
  70. if (!viewDriver) {
  71. return;
  72. }
  73. var node = viewDriver.state.nodes[nodeID];
  74. if (!node) {
  75. return;
  76. }
  77. if (methodName == "createAvatarBody") {
  78. let avatarName = 'avatar-' + self.kernel.moniker();
  79. if (nodeID == avatarName) {
  80. vwf_view.kernel.callMethod(nodeID, "showHideAvatar", [false]);
  81. }
  82. }
  83. }
  84. })
  85. }
  86. }
  87. export { AFrameARView as default }