@@ -19,7 +19,6 @@ import {
1919} from "three" ;
2020import type { PhoneDisplayLayout } from "./phoneScene.ts" ;
2121
22- const HALF_WIDTH = 1.04 ;
2322const HEIGHT = 2.2 ;
2423const DEPTH = 0.075 ;
2524const INSET = 0.026 ;
@@ -28,10 +27,24 @@ const BEVEL = 0.008;
2827// The hinge axis sits just above the inner screens so closed halves meet face to face.
2928const PIVOT_Z = DEPTH / 2 + 0.005 ;
3029const SPINE_RADIUS = PIVOT_Z + DEPTH / 2 - 0.002 ;
30+ /** Width over height of the unfolded inner display until a live frame reports its own. */
31+ export const DEFAULT_FOLD_INNER_ASPECT = 2076 / 2152 ;
32+ /**
33+ * Unfolded inner displays are near square in either orientation. Cover displays are
34+ * phone shaped (about 0.4-0.5, or 2-2.6 when rotated), so they never retune the body.
35+ */
36+ export const isFoldInnerAspect = ( aspect : number ) =>
37+ Number . isFinite ( aspect ) && aspect > 0.75 && aspect < 1.5 ;
3138
32- function panelPath ( side : "left" | "right" , inset : number , radius : number , hingeInset = 0 ) {
33- const left = side === "left" ? - HALF_WIDTH + inset : CREASE / 2 + hingeInset ;
34- const right = side === "left" ? - CREASE / 2 - hingeInset : HALF_WIDTH - inset ;
39+ function panelPath (
40+ halfWidth : number ,
41+ side : "left" | "right" ,
42+ inset : number ,
43+ radius : number ,
44+ hingeInset = 0 ,
45+ ) {
46+ const left = side === "left" ? - halfWidth + inset : CREASE / 2 + hingeInset ;
47+ const right = side === "left" ? - CREASE / 2 - hingeInset : halfWidth - inset ;
3548 const bottom = - HEIGHT / 2 + inset ;
3649 const top = HEIGHT / 2 - inset ;
3750 const path = new Shape ( ) ;
@@ -70,16 +83,22 @@ function roundedRectPath(width: number, height: number, radius: number) {
7083 return path ;
7184}
7285
73- function coverPath ( ) {
74- return roundedRectPath ( HALF_WIDTH - INSET * 2 - 0.02 , HEIGHT - INSET * 2 - 0.04 , 0.07 ) ;
86+ function coverPath ( halfWidth : number ) {
87+ return roundedRectPath ( halfWidth - INSET * 2 - 0.02 , HEIGHT - INSET * 2 - 0.04 , 0.07 ) ;
7588}
7689
77- /** A procedural book-style foldable: one fixed half, one half rotating around a shared hinge. */
90+ /**
91+ * A procedural book-style foldable: one fixed half, one half rotating around a shared hinge.
92+ * The inner display keeps the raw framebuffer's native aspect, portrait or landscape.
93+ */
7894export function createAndroidFoldScene (
7995 texture : Texture ,
8096 layout : PhoneDisplayLayout ,
8197 initialAngle : number ,
98+ innerAspect = DEFAULT_FOLD_INNER_ASPECT ,
8299) {
100+ const screenHeight = HEIGHT - 2 * INSET ;
101+ const halfWidth = ( innerAspect * screenHeight ) / 2 + INSET ;
83102 const root = new Group ( ) ;
84103 const orientation = new Group ( ) ;
85104 root . add ( orientation ) ;
@@ -146,7 +165,7 @@ export function createAndroidFoldScene(
146165
147166 function half ( group : Group , side : "left" | "right" , back : MeshPhysicalMaterial ) {
148167 const body = new Mesh (
149- new ExtrudeGeometry ( panelPath ( side , BEVEL , 0.1 , BEVEL ) , {
168+ new ExtrudeGeometry ( panelPath ( halfWidth , side , BEVEL , 0.1 , BEVEL ) , {
150169 depth : DEPTH - BEVEL * 2 ,
151170 bevelEnabled : true ,
152171 bevelSize : BEVEL ,
@@ -158,19 +177,25 @@ export function createAndroidFoldScene(
158177 ) ;
159178 body . position . z = - DEPTH / 2 + BEVEL ;
160179 group . add ( body ) ;
161- const frame = new Mesh ( new ShapeGeometry ( panelPath ( side , 0.01 , 0.095 , 0.002 ) , 12 ) , bezel ) ;
180+ const frame = new Mesh (
181+ new ShapeGeometry ( panelPath ( halfWidth , side , 0.01 , 0.095 , 0.002 ) , 12 ) ,
182+ bezel ,
183+ ) ;
162184 frame . position . z = DEPTH / 2 + 0.001 ;
163185 group . add ( frame ) ;
164186 // A back-facing shape mirrors X, so it is drawn from the opposite side's outline.
165187 const rear = new Mesh (
166- new ShapeGeometry ( panelPath ( side === "left" ? "right" : "left" , 0.01 , 0.095 , 0.002 ) , 12 ) ,
188+ new ShapeGeometry (
189+ panelPath ( halfWidth , side === "left" ? "right" : "left" , 0.01 , 0.095 , 0.002 ) ,
190+ 12 ,
191+ ) ,
167192 back ,
168193 ) ;
169194 rear . name = `${ side } -back` ;
170195 rear . rotation . y = Math . PI ;
171196 rear . position . set ( 0 , 0 , - DEPTH / 2 - 0.001 ) ;
172197 group . add ( rear ) ;
173- const geometry = new ShapeGeometry ( panelPath ( side , INSET , 0.076 ) ) ;
198+ const geometry = new ShapeGeometry ( panelPath ( halfWidth , side , INSET , 0.076 ) ) ;
174199 geometry . computeBoundingBox ( ) ;
175200 const display = new Mesh ( geometry , hitMaterial ) ;
176201 display . name = `${ side } -inner-screen` ;
@@ -183,8 +208,7 @@ export function createAndroidFoldScene(
183208 const innerRight = half ( right , "right" , backGlass ) ;
184209 // One indexed surface keeps adjacent pixels joined at the crease. The
185210 // physical halves move separately underneath it.
186- const screenWidth = 2 * ( HALF_WIDTH - INSET ) ;
187- const screenHeight = HEIGHT - 2 * INSET ;
211+ const screenWidth = 2 * ( halfWidth - INSET ) ;
188212 const screenGeometry = new PlaneGeometry ( screenWidth , screenHeight , 40 , 48 ) ;
189213 const screenPositions = screenGeometry . getAttribute ( "position" ) ;
190214 const screenUvs = screenGeometry . getAttribute ( "uv" ) ;
@@ -224,9 +248,9 @@ export function createAndroidFoldScene(
224248 spine . position . z = PIVOT_Z ;
225249 orientation . add ( spine ) ;
226250
227- const cover = new Mesh ( new ShapeGeometry ( coverPath ( ) ) , coverMaterial ) ;
251+ const cover = new Mesh ( new ShapeGeometry ( coverPath ( halfWidth ) ) , coverMaterial ) ;
228252 cover . name = "cover-screen" ;
229- cover . position . set ( - HALF_WIDTH / 2 , 0 , - DEPTH / 2 - 0.003 ) ;
253+ cover . position . set ( - halfWidth / 2 , 0 , - DEPTH / 2 - 0.003 ) ;
230254 cover . rotation . y = Math . PI ;
231255 leftBody . add ( cover ) ;
232256
@@ -236,7 +260,7 @@ export function createAndroidFoldScene(
236260 const islandWidth = 0.46 ;
237261 const islandHeight = 0.2 ;
238262 rearCamera . position . set (
239- HALF_WIDTH - 0.07 - islandWidth / 2 ,
263+ halfWidth - 0.07 - islandWidth / 2 ,
240264 HEIGHT / 2 - 0.08 - islandHeight / 2 ,
241265 - DEPTH / 2 - 0.002 ,
242266 ) ;
@@ -284,7 +308,7 @@ export function createAndroidFoldScene(
284308 [ 0.2 , 0.3 ] ,
285309 ] as const ) {
286310 const key = new Mesh ( new BoxGeometry ( 0.02 , length , DEPTH * 0.45 ) , frameMetal ) ;
287- key . position . set ( HALF_WIDTH + 0.008 , y , 0 ) ;
311+ key . position . set ( halfWidth + 0.008 , y , 0 ) ;
288312 right . add ( key ) ;
289313 }
290314
@@ -349,8 +373,9 @@ export function createAndroidFoldScene(
349373 return {
350374 root,
351375 orientation,
352- width : HALF_WIDTH * 2 ,
376+ width : halfWidth * 2 ,
353377 height : HEIGHT ,
378+ innerAspect,
354379 setAngle,
355380 setDisplay,
356381 screenPoint ( x : number , y : number , camera : Camera , captured = false ) {
0 commit comments