gearvrcontroller.js 4.5 KB

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