gearvrcontroller.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. this.simpleDef = {
  2. "extends": "proxy/aframe/abox.vwf",
  3. children: {
  4. "material": {
  5. "extends": "proxy/aframe/aMaterialComponent.vwf",
  6. "type": "component",
  7. "properties":{
  8. "color": "white"
  9. }
  10. }
  11. },
  12. "properties": {
  13. "position": "0 0 0",
  14. "height": 0.01,
  15. "width": 0.01,
  16. "depth": 1
  17. },
  18. children: {
  19. "pointer": {
  20. "extends": "proxy/aframe/abox.vwf",
  21. "properties": {
  22. "position": "0 0 -0.7",
  23. "height": 0.1,
  24. "width": 0.1,
  25. "depth": 0.1
  26. },
  27. children: {
  28. "material": {
  29. "extends": "proxy/aframe/aMaterialComponent.vwf",
  30. "type": "component",
  31. "properties":{
  32. "color": "green"
  33. }
  34. },
  35. "aabb-collider": {
  36. "extends": "proxy/aframe/aabb-collider-component.vwf",
  37. "type": "component",
  38. "properties": {
  39. debug: false,
  40. interval: 10,
  41. objects: ".gearvrhit"
  42. }
  43. },
  44. "myRayCaster": {
  45. "extends": "proxy/aframe/aentity.vwf",
  46. "properties": {},
  47. "children": {
  48. "raycaster": {
  49. "extends": "proxy/aframe/raycasterComponent.vwf",
  50. "type": "component",
  51. "properties": {
  52. recursive: false,
  53. interval: 10,
  54. far: 0.5,
  55. objects: ".gearvrcontroller"
  56. }
  57. }
  58. }
  59. }
  60. // "rotationText": {
  61. // "extends": "proxy/aframe/atext.vwf",
  62. // "properties":{
  63. // "value": "rot",
  64. // "side": "double",
  65. // }
  66. // }
  67. }
  68. }
  69. }
  70. }
  71. this.modelDef = {
  72. "extends": "proxy/aframe/agltfmodel.vwf",
  73. "properties": {
  74. "src": "#gearvr",
  75. "position": "0 0 0",
  76. "rotation": "0 180 0"
  77. },
  78. "children": {
  79. "animation-mixer": {
  80. "extends": "proxy/aframe/anim-mixer-component.vwf",
  81. "properties": {
  82. "clip": "*",
  83. "duration": 1
  84. }
  85. }
  86. }
  87. }
  88. this.createController = function (modelSrc) {
  89. let controllerDef = this.simpleDef;
  90. var newNode = {
  91. "extends": "proxy/aframe/aentity.vwf",
  92. "properties": {
  93. "position": [0, 0, -0.4]
  94. },
  95. children: {
  96. "controller": controllerDef
  97. }
  98. }
  99. if (modelSrc) {
  100. let controllerDef = this.modelDef;
  101. controllerDef.properties.src = modelSrc;
  102. newNode.children.controller = controllerDef;
  103. }
  104. let interpolation = {
  105. "extends": "proxy/aframe/interpolation-component.vwf",
  106. "type": "component",
  107. "properties": {
  108. "enabled": true
  109. }
  110. }
  111. this.children.create( "interpolation", interpolation );
  112. this.children.create("handVRNode", newNode);
  113. }
  114. this.updateVRControl = function(position, rotation){
  115. this.position = goog.vec.Vec3.createFromValues(position.x, position.y, position.z);
  116. this.rotation = goog.vec.Vec3.createFromValues(rotation.x, rotation.y, rotation.z);
  117. // this.position = position;
  118. // this.rotation = rotation;
  119. // this.handVRNode.controller.pointer.rotationText.value = rotation.x.toString() + rotation.y.toString() + rotation.z.toString();
  120. }
  121. this.createSimpleController = function(){
  122. if (this.handVRNode.controller) {
  123. this.handVRNode.children.delete(this.handVRNode.controller);
  124. let controllerDef = this.simpleDef;
  125. this.handVRNode.children.create("controller", controllerDef);
  126. }
  127. }
  128. this.createAvatarFromGLTF = function(modelSrc){
  129. if (this.handVRNode.controller) {
  130. this.handVRNode.children.delete(this.handVRNode.controller);
  131. let controllerDef = this.modelDef;
  132. controllerDef.properties.src = modelSrc;
  133. this.handVRNode.children.create("controller", controllerDef);
  134. }
  135. }
  136. this.initialize = function() {
  137. // this.future(0).update();
  138. }
  139. this.triggerdown = function() {
  140. this.handVRNode.controller.pointer.material.color = 'red'
  141. }
  142. this.triggerup = function() {
  143. this.handVRNode.controller.pointer.material.color = 'green'
  144. }