gearvrcontroller.js 3.2 KB

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