XRLightProbe: sự kiện reflectionchange

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Sự kiện WebXR reflectionchange kích hoạt mỗi khi bản đồ khối phản chiếu ước tính thay đổi. Điều này xảy ra do người dùng di chuyển qua các điều kiện ánh sáng khác nhau hoặc do thay đổi trực tiếp chính ánh sáng. Sự kiện này không thể hủy.

Cú pháp

Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt thuộc tính xử lý sự kiện.

js
addEventListener("reflectionchange", (event) => { })

onreflectionchange = (event) => { }

Loại sự kiện

Event.

Ví dụ

Sử dụng sự kiện reflectionchange

Bất cứ khi nào sự kiện reflectionchange kích hoạt trên một light probe, bạn có thể truy xuất một bản đồ khối cập nhật bằng cách gọi XRWebGLBinding.getReflectionCubeMap(). Điều này ít tốn kém hơn so với việc truy xuất thông tin ánh sáng với mỗi XRFrame.

js
const glBinding = new XRWebGLBinding(xrSession, gl);
const lightProbe = await xrSession.requestLightProbe();
let glCubeMap = glBinding.getReflectionCubeMap(lightProbe);

lightProbe.addEventListener("reflectionchange", () => {
  glCubeMap = glBinding.getReflectionCubeMap(lightProbe);
});

Thuộc tính xử lý sự kiện onreflectionchange

Sự kiện reflectionchange cũng có sẵn bằng cách sử dụng thuộc tính xử lý sự kiện onreflectionchange.

js
lightProbe.onreflectionchange = (event) => {
  glCubeMap = glBinding.getReflectionCubeMap(lightProbe);
};

Thông số kỹ thuật

Thông số kỹ thuật
WebXR Lighting Estimation API Level 1
# eventdef-xrlightprobe-reflectionchange
WebXR Lighting Estimation API Level 1
# dom-xrlightprobe-onreflectionchange

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

Xem thêm