VRLayerInit
已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。
非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。
WebVR API 的 VRLayerInit 字典代表一個您想在 VR 顯示器中呈現的內容層(一個 HTMLCanvasElement 或 OffscreenCanvas)。
注意:此字典是舊的 WebVR API 的一部分。它已被 WebXR Device API 取代。
您可以使用 VRDisplay.getLayers() 來檢索 VRLayerInit 物件,並使用 VRDisplay.requestPresent() 方法來呈現它們。
例項屬性
VRLayerInit.leftBounds已棄用-
定義了由
VRDisplay呈現的畫布的左紋理邊界。 VRLayerInit.rightBounds已棄用-
定義了由
VRDisplay呈現的畫布的右紋理邊界。 VRLayerInit.source已棄用-
定義了在呼叫
VRDisplay.submitFrame()時由VRDisplay呈現的畫布。
示例
// currently returns an empty array
let layers = vrDisplay.getLayers();
if (navigator.getVRDisplays) {
console.log("WebVR 1.1 supported");
// Then get the displays attached to the computer
navigator.getVRDisplays().then((displays) => {
// If a display is available, use it to present the scene
if (displays.length > 0) {
vrDisplay = displays[0];
console.log("Display found");
// Starting the presentation when the button is clicked: It can only be called in response to a user gesture
btn.addEventListener("click", () => {
vrDisplay.requestPresent([{ source: canvas }]).then(() => {
console.log("Presenting to WebVR display");
// Here it returns an array of VRLayerInit objects
layers = vrDisplay.getLayers();
// …
});
});
}
});
}
VRLayerInit 物件看起來像這樣:
const init = {
leftBounds: [
/* … */
],
rightBounds: [
/* … */
],
source: canvasReference,
};
注意:canvasReference 指的是 <canvas> 元素本身,而不是與該畫布關聯的 WebGL 上下文。其他兩個成員是陣列。
規範
此字典是舊的 WebVR API 的一部分,已被 WebXR Device API 取代。它已不再是標準化程序的一部分。
在所有瀏覽器都實現新的 WebXR API 之前,建議依靠 A-Frame、Babylon.js 或 Three.js 等框架,或 polyfill 來開發可在所有瀏覽器上執行的 WebXR 應用程式。有關更多資訊,請閱讀 Meta 的從 WebVR 移植到 WebXR 指南。
瀏覽器相容性
載入中…