2
2
var registerComponent = require ( '../core/component' ) . registerComponent ;
3
3
var bind = require ( '../utils/bind' ) ;
4
4
5
+ var AEntity = require ( '../core/a-entity' ) . AEntity ;
6
+
5
7
var trackedControlsUtils = require ( '../utils/tracked-controls' ) ;
6
8
var checkControllerPresentAndSetup = trackedControlsUtils . checkControllerPresentAndSetup ;
7
9
@@ -84,6 +86,7 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
84
86
}
85
87
86
88
this . onModelLoaded = this . onModelLoaded . bind ( this ) ;
89
+ this . onChildAttached = this . onChildAttached . bind ( this ) ;
87
90
this . jointEls = [ ] ;
88
91
this . controllerPresent = false ;
89
92
this . isPinched = false ;
@@ -102,6 +105,11 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
102
105
this . updateReferenceSpace = this . updateReferenceSpace . bind ( this ) ;
103
106
this . el . sceneEl . addEventListener ( 'enter-vr' , this . updateReferenceSpace ) ;
104
107
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 ) ;
105
113
} ,
106
114
107
115
update : function ( ) {
@@ -164,9 +172,21 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
164
172
165
173
this . updateHandModel ( ) ;
166
174
this . detectGesture ( ) ;
175
+ this . updateWristObject ( ) ;
167
176
}
168
177
} ,
169
178
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
+
170
190
updateHandModel : function ( ) {
171
191
if ( this . data . modelStyle === 'dots' ) {
172
192
this . updateHandDotsModel ( ) ;
@@ -348,6 +368,22 @@ module.exports.Component = registerComponent('hand-tracking-controls', {
348
368
mesh . rotation . set ( 0 , 0 , 0 ) ;
349
369
skinnedMesh . frustumCulled = false ;
350
370
skinnedMesh . material = new THREE . MeshStandardMaterial ( { color : this . data . modelColor } ) ;
371
+ this . setupChildrenEntities ( ) ;
351
372
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 ) ;
352
388
}
353
389
} ) ;
0 commit comments