@@ -52,10 +52,6 @@ AFRAME.registerComponent('dialog-popup', {
5252 type : 'string' ,
5353 default : 'click'
5454 } ,
55- defaultOpen : {
56- type : 'bool' ,
57- default : false
58- } ,
5955 openIconImage : {
6056 type : 'asset' ,
6157 default : ''
@@ -117,13 +113,23 @@ AFRAME.registerComponent('dialog-popup', {
117113 */
118114 init ( ) {
119115 this . spawnEntities ( ) ;
116+ this . cameraEl = document . querySelector ( '[camera]' ) ;
117+ } ,
118+ /**
119+ * If the component is open, ensure it always faces the camera.
120+ */
121+ tick ( ) {
122+ if ( this . isOpen ) {
123+ this . positionDialogPlane ( ) ;
124+ }
120125 } ,
121126 /**
122127 * Handles opening and closing the dialog plane.
123128 */
124129 toggleDialogOpen ( ) {
125130 this . isOpen = ! this . isOpen ;
126131 if ( this . dialogPlane ) {
132+ this . positionDialogPlane ( ) ;
127133 this . dialogPlane . setAttribute ( 'visible' , this . isOpen ) ;
128134 }
129135 } ,
@@ -306,13 +312,9 @@ AFRAME.registerComponent('dialog-popup', {
306312 } = this . data ;
307313
308314 const plane = document . createElement ( 'a-entity' ) ;
315+ plane . setAttribute ( 'id' , `${ this . el . getAttribute ( 'id' ) } --dialog-plane` ) ;
309316
310- // The dialog should always be a little closer to the camera than the icon.
311- const position = Object . assign ( { } , this . el . getAttribute ( 'position' ) ) ;
312- position . z += 1 ;
313-
314- plane . setAttribute ( 'visible' , this . data . defaultOpen ) ;
315- plane . setAttribute ( 'position' , position ) ;
317+ plane . setAttribute ( 'visible' , false ) ;
316318 plane . setAttribute ( 'geometry' , {
317319 primitive : 'plane' ,
318320 width : width + padding ,
@@ -330,8 +332,17 @@ AFRAME.registerComponent('dialog-popup', {
330332 plane . appendChild ( this . generateBody ( ) ) ;
331333
332334 this . dialogPlane = plane ;
335+
333336 return plane ;
334337 } ,
338+ positionDialogPlane ( ) {
339+ if ( this . dialogPlane ) {
340+ const vector = this . dialogPlane . object3D . parent . worldToLocal (
341+ this . cameraEl . object3D . getWorldPosition ( )
342+ ) ;
343+ this . dialogPlane . object3D . lookAt ( vector ) ;
344+ }
345+ } ,
335346 spawnEntities ( ) {
336347 const wrapper = document . createElement ( 'a-entity' ) ;
337348 wrapper . setAttribute ( 'id' , `${ this . el . getAttribute ( 'id' ) } --wrapper` ) ;
0 commit comments