VREyeParameters

已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。

非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。

VREyeParameters 介面是 WebVR API 的一部分,它包含了正確渲染給定眼睛的場景所需的所有資訊,包括視場資訊。

注意: 此介面是舊版 WebVR API 的一部分。它已被 WebXR Device API 取代。

可以透過 VRDisplay.getEyeParameters() 方法訪問此介面。

警告:此介面中的值不應用於計算檢視或投影矩陣。為了確保最廣泛的硬體相容性,請使用 VRFrameData 提供的矩陣。

例項屬性

VREyeParameters.offset 已棄用 只讀 非標準

表示使用者兩眼中心點到該眼睛中心點的偏移量,單位為米。

VREyeParameters.fieldOfView 已棄用 只讀 非標準

描述眼睛當前的視場,這可能會隨著使用者調整瞳距 (IPD) 而變化。

VREyeParameters.maximumFieldOfView 已棄用 只讀 非標準

描述當前眼睛支援的最大視場。

VREyeParameters.minimumFieldOfView 已棄用 只讀 非標準

描述當前眼睛支援的最小視場。

VREyeParameters.renderWidth 已棄用 只讀 非標準

描述每個眼睛視口推薦的渲染目標寬度(以畫素為單位)。

VREyeParameters.renderHeight 已棄用 只讀 非標準

描述每個眼睛視口推薦的渲染目標高度(以畫素為單位)。

示例

js
navigator.getVRDisplays().then((displays) => {
  // If a display is available, use it to present the scene
  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");

      // Set the canvas size to the size of the vrDisplay viewport

      const leftEye = vrDisplay.getEyeParameters("left");
      const rightEye = vrDisplay.getEyeParameters("right");

      canvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
      canvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);

      drawVRScene();
    });
  });
});

規範

此介面是舊的 WebVR API 的一部分,該 API 已被 WebXR Device API 取代。它已不再是標準的制定方向。

在所有瀏覽器都實現新的 WebXR API 之前,建議依靠 A-FrameBabylon.jsThree.js 等框架,或 polyfill 來開發可在所有瀏覽器上執行的 WebXR 應用程式。有關更多資訊,請閱讀 Meta 的從 WebVR 移植到 WebXR 指南。

瀏覽器相容性

另見