button.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. this.init = function(){
  2. this.height = this.height ? this.height : 0.3;
  3. this.width = this.width? this.width : 0.4;
  4. this.class = "clickable intersectable";
  5. this.baseColor = this.baseColor ? this.baseColor : 'white';
  6. this.hoverColor = this.hoverColor ? this.hoverColor : 'green';
  7. this.clickColor = this.clickColor ? this.clickColor : 'blue';
  8. let material = {
  9. "extends": "proxy/aframe/aMaterialComponent.vwf",
  10. "type": "component",
  11. "properties": {
  12. "transprent": true,
  13. "opacity": 0.3,
  14. "color": "white",
  15. "side": "double"
  16. }
  17. }
  18. let cursorListener = {
  19. "extends": "proxy/aframe/app-raycaster-listener-component.vwf",
  20. "type": "component"
  21. }
  22. let raycasterListener = {
  23. "extends": "proxy/aframe/app-raycaster-listener-component.vwf",
  24. "type": "component"
  25. }
  26. this.children.create('material', material);
  27. this.children.create('cursor-listener', cursorListener);
  28. this.children.create('raycaster-listener', raycasterListener);
  29. }
  30. this.intersectEventMethod = function(){
  31. this.material.opacity = 0.6;
  32. this.material.color = this.hoverColor
  33. }
  34. this.clearIntersectEventMethod = function(){
  35. this.material.opacity = 0.3;
  36. this.material.color = this.baseColor
  37. }
  38. this.mousedownAction = function(){
  39. this.triggerdownAction();
  40. }
  41. this.mouseupAction = function(){
  42. this.triggerupAction();
  43. }
  44. this.triggerdownAction = function(){
  45. this.material.color = this.clickColor;
  46. let target = this.getScene().findNode(this.target);
  47. target.doButtonTriggerdownAction(this.id);
  48. }
  49. this.triggerupAction = function(){
  50. this.material.color = this.baseColor;
  51. }