gearvrcontroller.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. // "rotationText": {
  36. // "extends": "http://vwf.example.com/aframe/atext.vwf",
  37. // "properties":{
  38. // "value": "rot",
  39. // "side": "double",
  40. // }
  41. // }
  42. }
  43. }
  44. }
  45. }
  46. this.modelDef = {
  47. "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
  48. "properties": {
  49. "src": "#gearvr",
  50. "position": "0 0 0",
  51. "rotation": "0 180 0"
  52. },
  53. "children": {
  54. "animation-mixer": {
  55. "extends": "http://vwf.example.com/aframe/anim-mixer-component.vwf",
  56. "properties": {
  57. "clip": "*",
  58. "duration": 1
  59. }
  60. }
  61. }
  62. }
  63. this.createController = function (modelSrc) {
  64. let controllerDef = this.simpleDef;
  65. var newNode = {
  66. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  67. "properties": {
  68. "position": [0, 0, 0]
  69. },
  70. children: {
  71. "controller": controllerDef
  72. }
  73. }
  74. if (modelSrc) {
  75. let controllerDef = this.modelDef;
  76. controllerDef.properties.src = modelSrc;
  77. newNode.children.controller = controllerDef;
  78. }
  79. let interpolation = {
  80. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  81. "type": "component",
  82. "properties": {
  83. "enabled": true
  84. }
  85. }
  86. this.children.create( "interpolation", interpolation );
  87. this.children.create("handVRNode", newNode);
  88. }
  89. this.updateVRControl = function(position, rotation){
  90. this.position = position;
  91. this.rotation = rotation;
  92. // this.handVRNode.controller.pointer.rotationText.value = rotation.x.toString() + rotation.y.toString() + rotation.z.toString();
  93. }
  94. this.createSimpleController = function(){
  95. if (this.handVRNode.controller) {
  96. this.handVRNode.children.delete(this.handVRNode.controller);
  97. let controllerDef = this.simpleDef;
  98. this.handVRNode.children.create("controller", controllerDef);
  99. }
  100. }
  101. this.createAvatarFromGLTF = function(modelSrc){
  102. if (this.handVRNode.controller) {
  103. this.handVRNode.children.delete(this.handVRNode.controller);
  104. let controllerDef = this.modelDef;
  105. controllerDef.properties.src = modelSrc;
  106. this.handVRNode.children.create("controller", controllerDef);
  107. }
  108. }
  109. this.initialize = function() {
  110. // this.future(0).update();
  111. }
  112. this.triggerdown = function() {
  113. this.handVRNode.controller.pointer.material.color = 'red'
  114. }
  115. this.triggerup = function() {
  116. this.handVRNode.controller.pointer.material.color = 'green'
  117. }