gearvrcontroller.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. this.simpleDef = {
  2. "extends": "http://vwf.example.com/aframe/abox.vwf",
  3. "properties": {
  4. "color": "white",
  5. "position": "0 0 0",
  6. "height": 0.01,
  7. "width": 0.01,
  8. "depth": 1,
  9. },
  10. children: {
  11. "pointer": {
  12. "extends": "http://vwf.example.com/aframe/abox.vwf",
  13. "properties": {
  14. "color": "green",
  15. "position": "0 0 -0.8",
  16. "height": 0.1,
  17. "width": 0.1,
  18. "depth": 0.1
  19. }
  20. },
  21. "interpolation":
  22. {
  23. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  24. "type": "component",
  25. "properties": {
  26. }
  27. }
  28. }
  29. }
  30. this.modelDef = {
  31. "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
  32. "properties": {
  33. "src": "#gearvr",
  34. "position": "0 0 0",
  35. "rotation": "0 180 0"
  36. },
  37. "children": {
  38. "animation-mixer": {
  39. "extends": "http://vwf.example.com/aframe/anim-mixer-component.vwf",
  40. "properties": {
  41. "clip": "*",
  42. "duration": 1
  43. }
  44. }
  45. }
  46. }
  47. this.createController = function (modelSrc) {
  48. let controllerDef = this.simpleDef;
  49. var newNode = {
  50. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  51. "properties": {
  52. "position": [0, 0, 0]
  53. },
  54. children: {
  55. "controller": controllerDef
  56. }
  57. }
  58. if (modelSrc) {
  59. let controllerDef = this.modelDef;
  60. controllerDef.properties.src = modelSrc;
  61. newNode.children.controller = controllerDef;
  62. }
  63. let interpolation = {
  64. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  65. "type": "component",
  66. "properties": {
  67. "enabled": true,
  68. "duration": 50,
  69. "deltaPos": 0,
  70. "deltaRot": 0
  71. }
  72. }
  73. this.children.create( "interpolation", interpolation );
  74. this.children.create("gearVRNode", newNode);
  75. }
  76. this.updateAvatarVRControl = function(position, rotation){
  77. this.rotation = rotation;
  78. this.position = position;
  79. }
  80. this.createSimpleController = function(){
  81. if (this.gearVRNode.controller) {
  82. this.gearVRNode.children.delete(this.gearVRNode.controller);
  83. let controllerDef = this.simpleDef;
  84. this.gearVRNode.children.create("controller", controllerDef);
  85. }
  86. }
  87. this.createAvatarFromGLTF = function(modelSrc){
  88. if (this.gearVRNode.controller) {
  89. this.gearVRNode.children.delete(this.gearVRNode.controller);
  90. let controllerDef = this.modelDef;
  91. controllerDef.properties.src = modelSrc;
  92. this.gearVRNode.children.create("controller", controllerDef);
  93. }
  94. }
  95. this.initialize = function() {
  96. // this.future(0).update();
  97. }
  98. this.triggerdown = function() {
  99. this.gearVRNode.controller.pointer.color = 'red'
  100. }
  101. this.triggerup = function() {
  102. this.gearVRNode.controller.pointer.color = 'green'
  103. }