Si ya ha utilizado la APIConcepto de API¿Qué es una API?Una API, siglas de Application Programming Interface o Interfaz de Programación de Apps, es un recopilatorio de código que se puede emplear para que varias apps se comuniquen entre ellas. Es algo que realiza una tarea equivalente a la interfaz de usuario al momento de promover la interacción entre persona y programa, solo que aplicado única y exclusivamente dentro del entorno del software.Aún cuando suene plus de dispositivo WebXR, ya ha recorrido la mayor parte del camino.
The WebXR Device API shipped last fall in Chrome 79. As stated then, the API implementation in Chrome is a work in progress. Chrome is happy to announce that some of the work is done. In Chrome 81, two new features have arrived:
Este artículo cubre la realidad aumentada¿Qué es la realidad aumentada?Tecnología que posibilita la reproducción en pantalla del entorno real captado por una cámara, sobre el que se superpone una capa de contenidos virtuales e interactivos generando una nueva realidad combinada. plus. Si ya ha utilizado WebXR Device API, le alegrará saber que hay muy pocas novedades que aprender. Entrar en una sesión de WebXR es básicamente lo mismo. Ejecutar un bucle de cuadro es básicamente lo mismo. Las diferencias radican en configuraciones que permiten mostrar el contentsEl contenido puede ser muy difícil de definir con precisión. Es una definición que se refiere a las declaraciones contenidas en un documento o publicación de cualquier tipo y puede incluir las tecnologías de la información y la comunicación. Esto cubre todos los tipos de medios como imágenes y texto. A parte de esto, en el campo de la optimización de motores de búsqueda, los términos duplicar contenido, contenido único, plus de forma adecuada para la realidad aumentada. Si no está familiarizado con los conceptos básicos de WebXR, debería leer mis publicaciones anteriores sobre la API del dispositivo WebXR, o al menos estar familiarizado con los temas que se tratan allí. Debe saber cómo solicitar e ingresar a una sesión y debe saber cómo ejecutar un bucle de tramas.
For information on positioning tests, see the companion article Positioning Virtual Objects in Real-World Views. The code in this article is based on the immersive AR session example (manifestation
source) from Immersive Web Working Group's WebXR Device API Samples.
Before diving into the code, you should use the Immersive Augmented Reality Session Sample
at least once. You will need a modern Android phone with Chrome 81 or later.
What is it for?
La realidad aumentada será una valiosa adición a muchas páginas web nuevas o existentes al permitirles implementar casos de uso de RA sin salir del browserUn navegador (además: browser) es una herramienta informática que te permite ver documentos y datos y navegar por la red. Los navegadores pueden mostrar distintos tipos de recursos de información; principalmente documentos HTML, a pesar de todo, además son posibles otros tipos de archivos y contenido multimedia, como PDF, JPEG, MPEG, GIF o el lenguaje de meta marcado. A través el uso de complementos especiales y la configuración respectivo, los plus. Por ejemplo, puede ayudar a las personsLas personas son personalidades imaginarias que representan a un determinado grupo objetivo. En el marketing online, las personas ayudan a entender mejor a los usuarios de un portal web o a los clientes de una tienda online. Concepto de personas Para que las personas puedan ejercer su efecto positivo, deben ser lo más detalladas viable. Esto conlleva un término exhaustiva de los grupos destinatarios para conseguir datos empíricos. La próxima plus a aprender en sitios educativos y permitir que los compradores potenciales visualicen objetos en su hogar mientras compran.
Consider the second use case. Imagine the simulation of placing a life-size representation of a virtual object in a real scene. Once placed, the image remains on the selected surface, appears the size it would have if the actual item were on that surface, and allows the user to move around it, as well as closer to or further from it. This gives viewers a deeper understanding of the object than is possible with a two-dimensional image.
I'm getting a little ahead of myself. To actually do what I've described, you need AR functionality and some means of detecting surfaces. This article covers the first one. The accompanying article on the WebXR Success Test API (linked above) covers the latter.
Requesting a session
Requesting a session is very similar to what you have seen before. First find out if the type of session you want is available on the current device by calling
xr.isSessionSupported (). Instead of asking 'immersive-vr' as before, request 'immersive-ar'.
if (navigator.xr) {
const supported = await navigator.xr.isSessionSupported('immersive-ar');
if (supported) {
xrButton.addEventListener('click', onButtonClicked);
xrButton.textContent = 'Enter AR';
xrButton.enabled = supported;
}
}
As before, this enables an 'Enter AR' button. When the user clicks on it, call
xr.requestSession (), also happening 'immersive-ar'.
let xrSession = null;
function onButtonClicked() {
if (!xrSession) {
navigator.xr.requestSession('immersive-ar')
.then((session) => {
xrSession = session;
xrSession.isImmersive = true;
xrButton.textContent = 'Exit AR';
onSessionStarted(xrSession);
});
} else {
xrSession.end();
}
}
A property of convenience
You probably noticed that I highlighted two lines in the last code sample. the XRSession the object appears to have a property called isImmersive. This is a convenience property that I have created myself and is not part of the specification. I'll use it later to make decisions about what to show the viewer. Why is this property not part of the API? Because your application may need to track this property differently, the spec authors decided to keep the API clean.
Enter a session
Remember that onSessionStarted () it looked like in my previous article:
function onSessionStarted(xrSession) {
xrSession.addEventListener('end', onSessionEnded);let canvas = document.createElement('canvas');
gl = canvas.getContext('webgl', { xrCompatible: true });
xrSession.updateRenderState({
baseLayer: new XRWebGLLayer(session, gl)
});
xrSession.requestReferenceSpace('local-floor')
.then((refSpace) => {
xrRefSpace = refSpace;
xrSession.requestAnimationFrame(onXRFrame);
});
}
I need to add a few things to account for the rendering of augmented reality. Turn off the background First, I'm going to determine if I need the background. This is the first place where I will use my convenience property.
function onSessionStarted(xrSession) {
xrSession.addEventListener('end', onSessionEnded);
if (session.isImmersive) {
removeBackground();
}
let canvas = document.createElement('canvas');
gl = canvas.getContext('webgl', { xrCompatible: true });
xrSession.updateRenderState({
baseLayer: new XRWebGLLayer(session, gl)
});
refSpaceType = xrSession.isImmersive ? 'local' : 'viewer';
xrSession.requestReferenceSpace(refSpaceType).then((refSpace) => {
xrSession.requestAnimationFrame(onXRFrame);
});
}
Reference spaces
My previous articles went through the reference spaces. The sample I'm describing uses two of them, so it's time to correct that omission.
A full explanation of the reference spaces would be longer than I can provide here. I'm only going to talk about reference spaces when it comes to augmented reality.
A reference space describes the relationship between the virtual world and the user's physical environment. It does this by:
- Specify the origin of the coordinate system used to express positions in the virtual world.
- Specify whether the user is expected to move within that coordinate system.
- If that coordinate system has preset limits. (The examples shown here do not use coordinate systems with preset limits.)
For all reference spaces, the X coordinate expresses left and right, Y expresses up and down, and Z expresses forward and backward. Positive values are correct, up and back, respectively.
The coordinates returned by XRFrame.getViewerPose () depend on what is requested
reference space type. More on that when we get to the frame loop. At this point, we must select a reference type that is appropriate for augmented reality. Again this uses my convenience property.
let refSpaceType
function onSessionStarted(xrSession) {
xrSession.addEventListener('end', onSessionEnded);
if (session.isImmersive) {
removeBackground();
}
let canvas = document.createElement('canvas');
gl = canvas.getContext('webgl', { xrCompatible: true });
xrSession.updateRenderState({
baseLayer: new XRWebGLLayer(session, gl)
});
refSpaceType = xrSession.isImmersive ? 'local' : 'viewer';
xrSession.requestReferenceSpace(refSpaceType).then((refSpace) => {
xrSession.requestAnimationFrame(onXRFrame);
});
}
If you have visited the Immersive Augmented Reality Session Sample
You will notice that initially the scene is static and not augmented reality. You can drag and slide your finger to move around the scene. If you click "START AR", the background disappears and you can move around the scene by moving the device. The modes use different types of reference spaces. The highlighted text above shows how it is selected. Use the following reference types:
local - The native origin is in the viewer's position at the time of the session creation. This means that the experience does not necessarily have a well defined floor and the exact position of the origin may vary depending on the platform. Although there are no preset limits for the space, it is expected that the content can be viewed without movement other than rotation. As you can see from our own AR example, some movement is possible within space.
viewer - Most frequently used for content presented online on the page, this space follows the display device. When passed to getViewerPose it does not provide tracking and therefore always reports a pose at the origin unless the application modifies it with XRReferenceSpace.getOffsetReferenceSpace (). The sample uses this to enable touch panning of the camera.
Running a frame loop
Conceptualmente, nada cambia con respecto a lo que hice en la sesión de virtual realityLa Realidad Virtual es un mundo artificial creado por medio de programas informáticos. Un usuario es teléfono celular en este mundo. La sección respectivo del mundo digital creado artificialmente se adapta a los movimientos y puntos de vista del usuario. Al ingresar en la realidad virtual, todos los movimientos del cuerpo pueden ser utilizados para la navegación y la percepción. "Las "gafas de realidad virtual" se usan normalmente como interfaz plus descrita en mis artículos anteriores. Pase el tipo de espacio de referencia a XRFrame.getViewerPose (). Return XRViewerPose will be for the current reference space type. Using
viewer as the default value allows a page to display content previews before user consent for AR or VR is requested. This illustrates an important point: online content uses the same frame loop as immersive content, reducing the amount of code that must be maintained.
function onXRFrame(hrTime, xrFrame) {
let xrSession = xrFrame.session;
xrSession.requestAnimationFrame(onXRFrame);
let xrViewerPose = xrFrame.getViewerPose(refSpaceType);
if (xrViewerPose) {
}
}
conclusion
This series of articles only covers the basics of implementing immersive content on the web. The Immersive Web Working Group introduces many more capabilities and use cases. WebXR Device API Samples. También acabamos de publicar un artículo de prueba de éxito que explica una API para detectar superficies y colocar elementos virtuales en una vista de cámara del mundo real. Échales un vistazo y mira el BlogEl término blog se usa para describir un diario virtual en Internet. El autor de un blogger puede publicar posts sobre cualquier tema. Los posts suelen estar presente de forma cronológica. El estilo de redacción de un blog suele ser informal y se escribe en primera persona. No obstante, además son posibles otros estilos, por ejemplo en el caso de los periódicos online, en los que la atención se centra plus de web.dev para ver más artículos durante el próximo año.
Photo by David grandmougin in Unsplash




