VREyeParameters
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.
Giao diện VREyeParameters của WebVR API đại diện cho tất cả thông tin cần thiết để hiển thị đúng một cảnh cho một mắt nhất định, bao gồm thông tin về trường nhìn.
Note: Giao diện này là một phần của WebVR API cũ. Nó đã được thay thế bởi WebXR Device API.
Giao diện này có thể truy cập qua phương thức VRDisplay.getEyeParameters().
Warning:
Các giá trị trong giao diện này không nên được sử dụng để tính toán ma trận view hoặc projection. Để đảm bảo khả năng tương thích phần cứng rộng nhất có thể, hãy sử dụng các ma trận được cung cấp bởi VRFrameData.
Thuộc tính phiên bản
VREyeParameters.offsetDeprecated Read only Non-standard-
Đại diện cho độ lệch từ điểm trung tâm giữa hai mắt của người dùng đến trung tâm của mắt, tính bằng mét.
VREyeParameters.fieldOfViewDeprecated Read only Non-standard-
Mô tả trường nhìn hiện tại của mắt, có thể thay đổi khi người dùng điều chỉnh khoảng cách đồng tử (IPD).
VREyeParameters.maximumFieldOfViewDeprecated Read only Non-standard-
Mô tả trường nhìn tối đa được hỗ trợ cho mắt hiện tại.
VREyeParameters.minimumFieldOfViewDeprecated Read only Non-standard-
Mô tả trường nhìn tối thiểu được hỗ trợ cho mắt hiện tại.
VREyeParameters.renderWidthDeprecated Read only Non-standard-
Mô tả chiều rộng render mục tiêu được khuyến nghị cho mỗi viewport mắt, tính bằng pixel.
VREyeParameters.renderHeightDeprecated Read only Non-standard-
Mô tả chiều cao render mục tiêu được khuyến nghị cho mỗi viewport mắt, tính bằng pixel.
Ví dụ
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();
});
});
});
Thông số kỹ thuật
Giao diệ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 theo lộ trình trở thành tiêu chuẩn.
Cho đến khi tất cả các trình duyệt đã triển khai WebXR APIs mới, khuyến nghị dựa vào các framework như A-Frame, Babylon.js, hoặc Three.js, hoặc một polyfill, để phát triển ứng dụng WebXR hoạt động trên tất cả trình duyệt. Đọc hướng dẫn Meta's Porting from WebVR to WebXR để biết thêm thông tin.