@@ -69,6 +69,10 @@ class FanController {
6969 #targetPositionX = 0 ;
7070 #targetPositionY = 0 ;
7171
72+ constructor ( ) {
73+ this . #container. isPickable = true ;
74+ }
75+
7276 update ( x , y ) {
7377 this . #container. lookAt ( this . lion . head . position ) ;
7478 this . #targetPositionX = - rule3 ( x , - 200 , 200 , - 250 , 250 ) ;
@@ -275,49 +279,42 @@ async function createAudioPlayer(name) {
275279 } ;
276280}
277281
282+ let playBlowingAudio ;
283+ let blowingAudio ;
284+
285+ function stopBlowingAudio ( ) {
286+ if ( blowingAudio ) {
287+ blowingAudio . pause ( ) ;
288+ blowingAudio = null ;
289+ }
290+ }
291+
278292const fanElement = document . querySelector ( '#fan_sphere' ) ;
293+ const fanNode = fanElement . asNativeType ( ) ;
294+ fanNode . isPickable = true ;
279295fanElement . addEventListener ( 'rayenter' , ( ) => {
280- fanElement . asNativeType ( ) . renderOutline = true ;
281- fanElement . asNativeType ( ) . outlineWidth = 2 ;
296+ fanNode . renderOverlay = true ;
282297} ) ;
283298fanElement . addEventListener ( 'rayleave' , ( ) => {
284- fanElement . asNativeType ( ) . renderOutline = false ;
299+ fanNode . renderOverlay = false ;
300+ isBlowing = false ;
301+ stopBlowingAudio ( ) ;
285302} ) ;
286303
287- let blowingAudio ;
288304fanElement . addEventListener ( 'raydown' , async ( ) => {
289305 isBlowing = true ;
290- if ( blowingAudio ) {
291- blowingAudio . load ( ) ;
292- blowingAudio . play ( ) ;
293- } else {
294- const play = await createAudioPlayer ( 'fan.mp3' ) ;
295- blowingAudio = play ( 1.0 ) ;
306+ if ( typeof playBlowingAudio !== 'function' ) {
307+ playBlowingAudio = await createAudioPlayer ( 'fan.mp3' ) ;
296308 }
309+ blowingAudio = playBlowingAudio ( 1.0 ) ;
297310} ) ;
298311fanElement . addEventListener ( 'rayup' , ( ) => {
299312 isBlowing = false ;
300- if ( blowingAudio ) {
301- blowingAudio . pause ( ) ;
302- }
313+ stopBlowingAudio ( ) ;
303314} ) ;
304315
305- // spaceDocument.watchInputEvent();
306- // spaceDocument.addEventListener('mouse', (event) => {
307- // const { inputData } = event;
308- // if (inputData.Action === 'move') {
309- // targetX = inputData.PositionX - screenWidth / 2;
310- // targetY = inputData.PositionY - screenHeight / 2;
311- // } else if (inputData.Action === 'down') {
312- // isBlowing = true;
313- // } else if (inputData.Action === 'up') {
314- // isBlowing = false;
315- // }
316- // });
317-
318316// let lastIndexFingerTipX = 0;
319317// let lastUpdateTimestamp = 0;
320-
321318// spaceDocument.addEventListener('handtracking', (event) => {
322319// const { inputData } = event;
323320// if (inputData.Type === 1) {
0 commit comments