傳統 2D 選單受限於螢幕空間,利用 JSR-184 將六個選單項目映射至立方體六個面,透過旋轉動畫實現直觀的空間導航。核心挑戰:立方體僅四個側面可見,需動態切換材質以呈現六項內容。
// 建立六個獨立 Appearance 物件,分別綁定網格體的六個面
Appearance[] appearances = new Appearance[6];
for (int i = 0; i < appearances.length; i++) {
appearances[i] = new Appearance();
appearances[i].setPolygonMode(polygonMode); // 共用多邊形模式 (如填充/線框)
mesh.setAppearance(i, appearances[i]); // 面索引 0-5 對應立方體六面
}
// 當前可見的三個面引用 (前、上、下)
Appearance frontFace, topFace, bottomFace;
// 旋轉動畫更新時,根據旋轉角度重新指派材質
frontFace = appearances[frontIndex]; // 正面
topFace = appearances[topIndex]; // 頂面
bottomFace= appearances[bottomIndex]; // 底面
// 套用對應選單圖示紋理
frontFace.setTexture(0, menuTextures[frontMenuIndex]);
topFace.setTexture(0, menuTextures[topMenuIndex]);
bottomFace.setTexture(0, menuTextures[bottomMenuIndex]);
IndexedTriangleArray 定義立方體幾何體,六個面共用頂點資料Texture2D 至 menuTextures[] 陣列Transform 物件控制立方體 Y 軸旋轉,配合 KeyframeSequence 實現緩動效果Appearance,僅替換 TexturesetTexture() 呼叫與狀態切換此技術展示了 JSR-184 除遊戲渲染外的創新 UI 應用潛力,以極低幾何體成本實現豐富的空間交互體驗。