22var  registerComponent  =  require ( '../core/component' ) . registerComponent ; 
33var  bind  =  require ( '../utils/bind' ) ; 
44
5+ var  AEntity  =  require ( '../core/a-entity' ) . AEntity ; 
6+ 
57var  trackedControlsUtils  =  require ( '../utils/tracked-controls' ) ; 
68var  checkControllerPresentAndSetup  =  trackedControlsUtils . checkControllerPresentAndSetup ; 
79
@@ -84,6 +86,7 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
8486    } 
8587
8688    this . onModelLoaded  =  this . onModelLoaded . bind ( this ) ; 
89+     this . onChildAttached  =  this . onChildAttached . bind ( this ) ; 
8790    this . jointEls  =  [ ] ; 
8891    this . controllerPresent  =  false ; 
8992    this . isPinched  =  false ; 
@@ -102,6 +105,11 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
102105    this . updateReferenceSpace  =  this . updateReferenceSpace . bind ( this ) ; 
103106    this . el . sceneEl . addEventListener ( 'enter-vr' ,  this . updateReferenceSpace ) ; 
104107    this . el . sceneEl . addEventListener ( 'exit-vr' ,  this . updateReferenceSpace ) ; 
108+     this . el . addEventListener ( 'child-attached' ,  this . onChildAttached ) ; 
109+   } , 
110+ 
111+   onChildAttached : function  ( evt )  { 
112+     this . addChildEntity ( evt . detail . el ) ; 
105113  } , 
106114
107115  update : function  ( )  { 
@@ -164,9 +172,21 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
164172
165173      this . updateHandModel ( ) ; 
166174      this . detectGesture ( ) ; 
175+       this . updateWristObject ( ) ; 
167176    } 
168177  } , 
169178
179+   updateWristObject : ( function  ( )  { 
180+     var  jointPose  =  new  THREE . Matrix4 ( ) ; 
181+     return  function  ( )  { 
182+       var  wristObject3D  =  this . wristObject3D ; 
183+       if  ( ! wristObject3D )  {  return ;  } 
184+       jointPose . fromArray ( this . jointPoses ,  WRIST_INDEX  *  16 ) ; 
185+       wristObject3D . position . setFromMatrixPosition ( jointPose ) ; 
186+       wristObject3D . quaternion . setFromRotationMatrix ( jointPose ) ; 
187+     } ; 
188+   } ) ( ) , 
189+ 
170190  updateHandModel : function  ( )  { 
171191    if  ( this . data . modelStyle  ===  'dots' )  { 
172192      this . updateHandDotsModel ( ) ; 
@@ -348,6 +368,22 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
348368    mesh . rotation . set ( 0 ,  0 ,  0 ) ; 
349369    skinnedMesh . frustumCulled  =  false ; 
350370    skinnedMesh . material  =  new  THREE . MeshStandardMaterial ( { color : this . data . modelColor } ) ; 
371+     this . setupChildrenEntities ( ) ; 
351372    this . el . setObject3D ( 'mesh' ,  mesh ) ; 
373+   } , 
374+ 
375+   setupChildrenEntities : function  ( )  { 
376+     var  childrenEls  =  this . el . children ; 
377+     this . wristObject3D  =  new  THREE . Object3D ( ) ; 
378+     for  ( var  i  =  0 ;  i  <  childrenEls . length ;  ++ i )  { 
379+       if  ( ! ( childrenEls [ i ]  instanceof  AEntity ) )  {  continue ;  } 
380+       this . addChildEntity ( childrenEls [ i ] ) ; 
381+     } 
382+     this . el . sceneEl . object3D . add ( this . wristObject3D ) ; 
383+   } , 
384+ 
385+   addChildEntity : function  ( childEl )  { 
386+     if  ( ! ( childEl  instanceof  AEntity ) )  {  return ;  } 
387+     this . wristObject3D . add ( childEl . object3D ) ; 
352388  } 
353389} ) ; 
0 commit comments