VRLayerInit

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

Từ điển VRLayerInit của WebVR API đại diện cho một lớp nội dung (HTMLCanvasElement hoặc OffscreenCanvas) mà bạn muốn trình bày trong màn hình VR.

Note: Từ điển này là một phần của WebVR API cũ. Nó đã được thay thế bởi WebXR Device API.

Bạn có thể lấy các đối tượng VRLayerInit bằng cách sử dụng VRDisplay.getLayers(), và trình bày chúng bằng phương thức VRDisplay.requestPresent().

Thuộc tính phiên bản

VRLayerInit.leftBounds Deprecated

Xác định giới hạn kết cấu bên trái của canvas mà nội dung sẽ được trình bày bởi VRDisplay.

VRLayerInit.rightBounds Deprecated

Xác định giới hạn kết cấu bên phải của canvas mà nội dung sẽ được trình bày bởi VRDisplay.

VRLayerInit.source Deprecated

Xác định canvas mà nội dung sẽ được trình bày bởi VRDisplay khi VRDisplay.submitFrame() được gọi.

Ví dụ

js
// 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();

          // …
        });
      });
    }
  });
}

Đối tượng VRLayerInit trông giống như thế này:

js
const init = {
  leftBounds: [
    /* … */
  ],
  rightBounds: [
    /* … */
  ],
  source: canvasReference,
};

Note: canvasReference đề cập đến phần tử <canvas> chính nó, không phải ngữ cảnh WebGL liên quan đến canvas. Hai thành viên còn lại là các mảng.

Thông số kỹ thuật

Từ điển này là một phần của WebVR API cũ đã được thay thế bởi WebXR Device API. Nó không còn trên đường trở thành tiêu chuẩn.

Tương thích trình duyệt

Xem thêm