@@ -331,6 +331,108 @@ it("faces a display handed off by native rotation without requesting another sen
331331 viewer . dispose ( ) ;
332332} ) ;
333333
334+ // Recorded from the iPhone Duo simulator: a fold button across the closed
335+ // position lets the cover report the inner display's orientation before handing
336+ // off. A button's pending angle reaches the viewer as a hinge preview first.
337+ it ( "presents fold buttons centered on the hinge: book, tablet, and an upright closed phone" , async ( ) => {
338+ // Configurations arrive while the view is still easing; time only advances to settle.
339+ let now = 0 ;
340+ vi . stubGlobal ( "performance" , { now : ( ) => now } ) ;
341+ const { viewer, draw, state, onOrientationRequested } = fixture ( false ) ;
342+ const loaded = asset ( ) ;
343+ models . resolve ( { asset : loaded , dispose : vi . fn ( ) } ) ;
344+ await Promise . resolve ( ) ;
345+ viewer . resize ( 500 , 700 , 2 ) ;
346+ const cover = { width : 1398 , height : 2034 , screenId : 1 , hingePose : null } as const ;
347+ const inner = { width : 2007 , height : 2853 , screenId : 3 , hingePose : null } as const ;
348+ const press = (
349+ angle : number ,
350+ configs : ReadonlyArray < { orientation : "portrait" | "landscape_left" ; screenId : 1 | 3 } > ,
351+ ) => {
352+ viewer . setHingePreview ( angle ) ;
353+ configs . forEach ( ( config , index ) => {
354+ viewer . setScreen ( {
355+ ...( config . screenId === 1 ? cover : inner ) ,
356+ ...config ,
357+ hingeAngle : angle ,
358+ } ) ;
359+ // The command reply follows the first configuration.
360+ if ( index === 0 ) viewer . setHingePreview ( null ) ;
361+ draw ( ) ;
362+ } ) ;
363+ now += 5_000 ;
364+ draw ( ) ;
365+ draw ( ) ;
366+ } ;
367+ const expectInnerFacing = ( minimum : number ) => {
368+ for ( const name of [ "inner-display-left" , "inner-display-right" ] ) {
369+ const mesh = loaded . getObjectByName ( name ) as Mesh ;
370+ const normal = new Vector3 ( )
371+ . fromBufferAttribute ( mesh . geometry . getAttribute ( "normal" ) , 0 )
372+ . transformDirection ( mesh . matrixWorld ) ;
373+ expect ( normal . z ) . toBeGreaterThan ( minimum ) ;
374+ }
375+ } ;
376+ const upright = new Rotation ( ) . setFromEuler ( new Euler ( 0 , Math . PI / 2 , 0 , "YXZ" ) ) ;
377+ const closeAndExpectUpright = ( ) => {
378+ press ( 0 , [
379+ { screenId : 3 , orientation : "landscape_left" } ,
380+ { screenId : 1 , orientation : "portrait" } ,
381+ ] ) ;
382+ expect ( state . views . at ( - 1 ) ! . quaternion . angleTo ( upright ) ) . toBeLessThan ( 0.00001 ) ;
383+ } ;
384+ viewer . setScreen ( { ...inner , orientation : "landscape_left" , hingeAngle : 180 } ) ;
385+ draw ( ) ;
386+ closeAndExpectUpright ( ) ;
387+ press ( 90 , [
388+ { screenId : 1 , orientation : "portrait" } ,
389+ { screenId : 1 , orientation : "landscape_left" } ,
390+ { screenId : 3 , orientation : "landscape_left" } ,
391+ // Election can flap back to the cover once before settling.
392+ { screenId : 1 , orientation : "landscape_left" } ,
393+ { screenId : 3 , orientation : "landscape_left" } ,
394+ ] ) ;
395+ expectInnerFacing ( 0.45 ) ;
396+ // Opening the book flat faces the whole tablet; folding back centers the book again.
397+ press ( 180 , [ { screenId : 3 , orientation : "landscape_left" } ] ) ;
398+ expectInnerFacing ( 0.99 ) ;
399+ press ( 90 , [ { screenId : 3 , orientation : "landscape_left" } ] ) ;
400+ expectInnerFacing ( 0.45 ) ;
401+ closeAndExpectUpright ( ) ;
402+ expect ( onOrientationRequested ) . not . toHaveBeenCalled ( ) ;
403+ viewer . dispose ( ) ;
404+ } ) ;
405+
406+ it ( "eases a fold button's hinge while a pinch follows the fingers" , async ( ) => {
407+ let now = 0 ;
408+ vi . stubGlobal ( "performance" , { now : ( ) => now } ) ;
409+ const { viewer, draw } = fixture ( false ) ;
410+ const loaded = asset ( ) ;
411+ models . resolve ( { asset : loaded , dispose : vi . fn ( ) } ) ;
412+ await Promise . resolve ( ) ;
413+ viewer . resize ( 500 , 700 , 2 ) ;
414+ viewer . setScreen ( {
415+ width : 2007 ,
416+ height : 2853 ,
417+ orientation : "landscape_left" ,
418+ screenId : 3 ,
419+ hingeAngle : 180 ,
420+ } ) ;
421+ draw ( ) ;
422+ const leaf = loaded . getObjectByName ( "left-half" ) ! ;
423+ const open = ( ( 180 - 90 ) * Math . PI ) / 360 ;
424+ viewer . setHingePreview ( 90 ) ;
425+ draw ( ) ;
426+ expect ( leaf . rotation . y ) . toBeGreaterThan ( 0 ) ;
427+ expect ( leaf . rotation . y ) . toBeLessThan ( open * 0.9 ) ;
428+ now += 1_000 ;
429+ draw ( ) ;
430+ expect ( leaf . rotation . y ) . toBeCloseTo ( open ) ;
431+ viewer . setHingePreview ( 30 , true ) ;
432+ expect ( leaf . rotation . y ) . toBeCloseTo ( ( ( 180 - 30 ) * Math . PI ) / 360 ) ;
433+ viewer . dispose ( ) ;
434+ } ) ;
435+
334436it . each ( [ "book" , "laptop" , "open" ] as const ) (
335437 "faces native cover readback for %s even when configuration arrives before the model" ,
336438 async ( hingePose ) => {
@@ -402,7 +504,7 @@ it("keeps default-zoom orbits framed across folds and fits the current assembly"
402504 viewer . dispose ( ) ;
403505} ) ;
404506
405- it ( "previews hinge articulation while preserving the laptop lid orientation and blocking unconfirmed input" , async ( ) => {
507+ it ( "pinches the hinge while preserving the laptop lid orientation and blocking unconfirmed input" , async ( ) => {
406508 const { viewer, draw, pending } = fixture ( ) ;
407509 const loaded = asset ( ) ;
408510 models . resolve ( { asset : loaded , dispose : vi . fn ( ) } ) ;
@@ -420,7 +522,7 @@ it("previews hinge articulation while preserving the laptop lid orientation and
420522 const lid = loaded . getObjectByName ( "right-half" ) ! ;
421523 const presentation = lid . getWorldQuaternion ( new Rotation ( ) ) ;
422524 for ( const value of [ 127 , 50 , 170 ] ) {
423- viewer . setHingePreview ( value ) ;
525+ viewer . setHingePreview ( value , true ) ;
424526 draw ( ) ;
425527 expect ( loaded . getObjectByName ( "left-half" ) ! . rotation . y ) . toBeCloseTo (
426528 ( ( 180 - value ) * Math . PI ) / 360 ,
@@ -438,7 +540,7 @@ it("previews hinge articulation while preserving the laptop lid orientation and
438540 draw ( ) ;
439541 expect ( lid . getWorldQuaternion ( new Rotation ( ) ) . angleTo ( presentation ) ) . toBeLessThan ( 0.00001 ) ;
440542 }
441- viewer . setHingePreview ( null ) ;
543+ viewer . setHingePreview ( null , true ) ;
442544 draw ( ) ;
443545 expect ( pending . size ) . toBe ( 0 ) ;
444546 expect ( lid . getWorldQuaternion ( new Rotation ( ) ) . angleTo ( presentation ) ) . toBeLessThan ( 0.00001 ) ;
@@ -480,6 +582,42 @@ it("does not restart an animated preset on duplicate native configurations", asy
480582 viewer . dispose ( ) ;
481583} ) ;
482584
585+ it . each ( [ true , false ] ) (
586+ "stands Tent on both edges when the cover reads it back (configuration before model: %s)" ,
587+ async ( configurationFirst ) => {
588+ // Recorded from the iPhone Duo simulator: Tent can rest with the cover active.
589+ const { viewer, draw } = fixture ( ) ;
590+ viewer . resize ( 500 , 700 , 2 ) ;
591+ const tent = {
592+ width : 1398 ,
593+ height : 2034 ,
594+ orientation : "portrait" ,
595+ screenId : 1 ,
596+ hingeAngle : 80 ,
597+ hingePose : "tent" ,
598+ } as const ;
599+ if ( configurationFirst ) viewer . setScreen ( tent ) ;
600+ const loaded = asset ( ) ;
601+ models . resolve ( { asset : loaded , dispose : vi . fn ( ) } ) ;
602+ await Promise . resolve ( ) ;
603+ if ( ! configurationFirst ) viewer . setScreen ( tent ) ;
604+ draw ( ) ;
605+ draw ( ) ;
606+ // Each leaf runs from the hinge down to the surface it rests on.
607+ for ( const [ name , outward ] of [
608+ [ "left-half" , - 1 ] ,
609+ [ "right-half" , 1 ] ,
610+ ] as const ) {
611+ const leaf = loaded . getObjectByName ( name ) ! ;
612+ const down = new Vector3 ( outward , 0 , 0 ) . applyQuaternion (
613+ leaf . getWorldQuaternion ( new Rotation ( ) ) ,
614+ ) ;
615+ expect ( down . y ) . toBeLessThan ( - 0.4 ) ;
616+ }
617+ viewer . dispose ( ) ;
618+ } ,
619+ ) ;
620+
483621it ( "lets standalone rotation leave Laptop and Tent and stand a closed device upright after hinge edits" , async ( ) => {
484622 const { viewer, draw, state } = fixture ( ) ;
485623 models . resolve ( { asset : asset ( ) , dispose : vi . fn ( ) } ) ;
@@ -672,7 +810,7 @@ it.each(["left", "right"] as const)(
672810 const partner = loaded . getObjectByName ( "left-half" ) ! ;
673811 const partnerStart = partner . getWorldQuaternion ( new Rotation ( ) ) ;
674812 for ( const value of [ 150 , 90 , 30 , 0 , 30 , 90 , 180 ] ) {
675- viewer . setHingePreview ( value ) ;
813+ viewer . setHingePreview ( value , true ) ;
676814 draw ( ) ;
677815 expect ( leaf . getWorldQuaternion ( new Rotation ( ) ) . angleTo ( orientation ) ) . toBeLessThan ( 1e-6 ) ;
678816 if ( value === 90 )
@@ -682,7 +820,7 @@ it.each(["left", "right"] as const)(
682820 ? { ...inner , width : 1398 , height : 2034 , screenId : 1 , hingeAngle : value , hingePose : null }
683821 : { ...inner , hingeAngle : value , hingePose : null } ;
684822 viewer . setScreen ( next ) ;
685- viewer . setHingePreview ( null ) ;
823+ viewer . setHingePreview ( null , true ) ;
686824 draw ( ) ;
687825 viewer . setScreen ( { ...next } ) ; // Late native readback cannot change the view.
688826 draw ( ) ;
0 commit comments