VRFrameData: timestamp 屬性

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

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

VRFrameData 介面的只讀屬性 timestamp 返回一個持續遞增的時間戳值,表示幀更新發生的時間。

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

時間戳有助於確定位置狀態資料是否已從硬體更新。由於值是單調遞增的,因此可以比較它們以確定更新的順序 — 新值將始終大於或等於舊值。

對於給定的 VRDisplay,當首次呼叫 VRDisplay.getFrameData() 時,時間戳從 0 開始。

一個 DOMHighResTimeStamp 物件。

示例

js
const frameData = new VRFrameData();
let vrDisplay;

navigator.getVRDisplays().then((displays) => {
  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(() => {
      drawVRScene();
    });
  });
});

// WebVR: Draw the scene for the WebVR display.
function drawVRScene() {
  // WebVR: Request the next frame of the animation
  vrSceneFrame = vrDisplay.requestAnimationFrame(drawVRScene);

  // Populate frameData with the data of the next frame to display
  vrDisplay.getFrameData(frameData);

  // grab the current timestamp on each run of the rendering loop
  // and do something with it
  frameData.timestamp;

  // …

  // WebVR: Indicates that we are ready to present the rendered frame to the VR display
  vrDisplay.submitFrame();
}

規範

此屬性是舊的 WebVR API 的一部分,已被 WebXR Device API 取代。它已不再是標準的開發方向。

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

瀏覽器相容性

另見