22AFRAME . registerComponent ( 'brush' ,  { 
33  schema : { 
44    color : { type : 'color' ,  default : '#ef2d5e' } , 
5-     size : { default : 0.01 ,  min : 0.001 ,  max : 0.3 } , 
5+     size : { default : 0.01 ,  min : 0.001 ,  max : 1.0 } , 
6+     pressureMultiplier : { default : 5.0 ,  min : 0.01 ,  max : 10.0 } , 
67    enabled : { default : true } , 
78    hand : { default : 'left' } 
89  } , 
@@ -15,6 +16,7 @@ AFRAME.registerComponent('brush', {
1516    this . stroke  =  null ; 
1617    this . buttonsDown  =  0 ; 
1718    this . touches  =  0 ; 
19+     this . sizeFactor  =  1.0 ; 
1820
1921    this . onTouchStarted  =  this . onTouchStarted . bind ( this ) ; 
2022    el . addEventListener ( 'tiptouchstart' ,  this . onTouchStarted ) ; 
@@ -26,6 +28,9 @@ AFRAME.registerComponent('brush', {
2628    this . onButtonUp  =  this . onButtonUp . bind ( this ) ; 
2729    el . addEventListener ( 'buttonup' ,  this . onButtonUp ) ; 
2830
31+     this . onButtonChanged  =  this . onButtonChanged . bind ( this ) ; 
32+     el . addEventListener ( 'buttonchanged' ,  this . onButtonChanged ) ; 
33+ 
2934    this . onControllerConnected  =  this . onControllerConnected . bind ( this ) ; 
3035    el . addEventListener ( 'controllerconnected' ,  this . onControllerConnected ) ; 
3136
@@ -68,6 +73,16 @@ AFRAME.registerComponent('brush', {
6873    this . painting  =  false ; 
6974  } , 
7075
76+   onButtonChanged : function  ( evt )  { 
77+     if  ( ! this . data . enabled )  {  return ;  } 
78+     if  ( ! this . painting )  {  return ;  } 
79+     if  ( evt . detail . state . value  ===  1 )  { 
80+       this . sizeFactor  =  1.0 ; 
81+     }  else  { 
82+       this . sizeFactor  =  evt . detail . state . value  *  this . data . pressureMultiplier ; 
83+     } 
84+   } , 
85+ 
7186  tick : ( function  ( )  { 
7287    var  position  =  new  THREE . Vector3 ( ) ; 
7388    var  rotation  =  new  THREE . Quaternion ( ) ; 
@@ -84,12 +99,13 @@ AFRAME.registerComponent('brush', {
8499      } 
85100      this . el . object3D . matrixWorld . decompose ( position ,  rotation ,  scale ) ; 
86101      var  pointerPosition  =  this . getPointerPosition ( position ,  rotation ) ; 
102+       this . stroke . setSize ( this . data . size  *  this . sizeFactor ) ; 
87103      this . stroke . addPoint ( position ,  rotation ,  pointerPosition ) ; 
88104    } ; 
89105  } ) ( ) , 
90106
91107  startNewStroke : function  ( )  { 
92-     this . stroke  =  this . system . addNewStroke ( this . color ,  this . data . size ) ; 
108+     this . stroke  =  this . system . addNewStroke ( this . color ,  this . data . size   *   this . sizeFactor ) ; 
93109  } , 
94110
95111  getPointerPosition : ( function  ( )  { 
0 commit comments