wmrvrcontroller.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // "interpolation":
  38. // {
  39. // "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  40. // "type": "component",
  41. // "properties": {
  42. // "enabled": true
  43. // }
  44. // }
  45. }
  46. }
  47. this.modelDef = {
  48. "extends": "http://vwf.example.com/aframe/agltfmodel.vwf",
  49. "properties": {
  50. "src": "#wmrvr",
  51. "position": "0 0 0",
  52. "rotation": "0 180 0"
  53. },
  54. "children": {
  55. "animation-mixer": {
  56. "extends": "http://vwf.example.com/aframe/anim-mixer-component.vwf",
  57. "properties": {
  58. "clip": "*",
  59. "duration": 1
  60. }
  61. }
  62. }
  63. }
  64. this.createController = function (modelSrc) {
  65. let controllerDef = this.simpleDef;
  66. var newNode = {
  67. "extends": "http://vwf.example.com/aframe/aentity.vwf",
  68. "properties": {
  69. "position": [0, 0, 0]
  70. },
  71. children: {
  72. "controller": controllerDef
  73. }
  74. }
  75. if (modelSrc) {
  76. let controllerDef = this.modelDef;
  77. controllerDef.properties.src = modelSrc;
  78. newNode.children.controller = controllerDef;
  79. }
  80. let interpolation = {
  81. "extends": "http://vwf.example.com/aframe/interpolation-component.vwf",
  82. "type": "component",
  83. "properties": {
  84. "enabled": true
  85. }
  86. }
  87. this.children.create( "interpolation", interpolation );
  88. this.children.create("handVRNode", newNode);
  89. }
  90. this.updateVRControl = function(position, rotation){
  91. this.rotation = rotation;
  92. this.position = position;
  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. }