神刀安全网

WebVR spec 1.0

Hardware that enables Virtual Reality applications requires high-precision, low-latency interfaces to deliver an acceptable experience. Other interfaces, such as device orientation events, can be repurposed to surface VR input but doing so dilutes the interface’s original intent and often does not provide the precision necessary for high-quality VR. The WebVR API provides purpose-built interfaces to VR hardware to allow developers to build compelling, comfortable VR experiences.

2. DOM Interfaces

This section describes the interfaces and functionality added to the DOM to support runtime access to the functionality described above.

2.1. VRDisplay

The VRDisplay interface forms the base of all VR devices supported by this API. It includes generic information such as device IDs and descriptions.

interface VRDisplay#vrdisplayReferenced in:2.1. VRDisplay2.1.1. Attributes (2) (3) (4) (5) (6) (7) (8) (9) (10) (11) (12) (13) (14) (15) (16) (17) (18) (19) (20) (21) (22)2.2. VRLayer2.2.1. Attributes (2)2.3. VRDisplayCapabilities2.3.1. Attributes (2) (3) (4) (5) (6) (7)2.6.1. Attributes2.9. Navigator Interface extension (2)2.9.1. Attributes (2) (3)2.11.1. Attributes3. Security Considerations (2) (3) : EventTarget {   readonly attribute boolean isConnected;   readonly attribute boolean isPresenting;    /**    * Dictionary of capabilities describing the VRDisplay.    */   [Constant] readonly attribute VRDisplayCapabilities capabilities;    /**    * If this VRDisplay supports room-scale experiences, the optional    * stage attribute contains details on the room-scale parameters.    */   readonly attribute VRStageParameters? stageParameters;    /* Return the current VREyeParameters for the given eye. */   VREyeParameters getEyeParameters(VREye whichEye);    /**    * An identifier for this distinct VRDisplay. Used as an    * association point in the Gamepad API.    */   [Constant] readonly attribute unsigned long displayId;    /**    * A display name, a user-readable name identifying it.    */   [Constant] readonly attribute DOMString displayName;    /**    * Return a VRPose containing the future predicted pose of the VRDisplay    * when the current frame will be presented. The value returned will not    * change until JavaScript has returned control to the browser.    *    * The VRPose will contain the position, orientation, velocity,    * and acceleration of each of these properties.    */   [NewObject] VRPose getPose();    /**    * Return the current instantaneous pose of the VRDisplay, with no    * prediction applied.    */   [NewObject] VRPose getImmediatePose();    /**    * Reset the pose for this display, treating its current position and    * orientation as the "origin/zero" values. VRPose.position,    * VRPose.orientation, and VRStageParameters.sittingToStandingTransform may be    * updated when calling resetPose(). This should be called in only    * sitting-space experiences.    */   void resetPose();    /**    * z-depth defining the near plane of the eye view frustum    * enables mapping of values in the render target depth    * attachment to scene coordinates. Initially set to 0.01.    */   attribute double depthNear;    /**    * z-depth defining the far plane of the eye view frustum    * enables mapping of values in the render target depth    * attachment to scene coordinates. Initially set to 10000.0.    */   attribute double depthFar;    /**    * The callback passed to `requestAnimationFrame` will be called    * any time a new frame should be rendered. When the VRDisplay is    * presenting the callback will be called at the native refresh    * rate of the HMD. When not presenting this function acts    * identically to how window.requestAnimationFrame acts. Content should    * make no assumptions of frame rate or vsync behavior as the HMD runs    * asynchronously from other displays and at differing refresh rates.    */   [Throws] long requestAnimationFrame(FrameRequestCallback callback);    /**    * Passing the value returned by `requestAnimationFrame` to    * `cancelAnimationFrame` will unregister the callback.    */   [Throws] void cancelAnimationFrame(long handle);    /**    * Begin presenting to the VRDisplay. Must be called in response to a user gesture.    * Repeat calls while already presenting will update the VRLayers being displayed.    */   Promise<void> requestPresent(sequence<VRLayer> layers);    /**    * Stops presenting to the VRDisplay.    */   Promise<void> exitPresent();    /**    * Get the layers currently being presented.    */   sequence<VRLayer> getLayers();    /**    * The VRLayer provided to the VRDisplay will be captured and presented    * in the HMD. Calling this function has the same effect on the source    * canvas as any other operation that uses its source image, and canvases    * created without preserveDrawingBuffer set to true will be cleared.    */   void submitFrame(optional VRPose pose); };

2.1.1. Attributes

isConnected #dom-vrdisplay-isconnected Referenced in: The isConnected attribute MUST return the VRDisplay ‘s connected state.

isPresenting #dom-vrdisplay-ispresenting Referenced in: The isPresenting attribute MUST return the VRDisplay ‘s presentation state.

capabilities #dom-vrdisplay-capabilities Referenced in: The capabilities attribute MUST return the VRDisplay ‘s VRDisplayCapabilities object, a dictionary of capabilities describing the VRDisplay .

getEyeParameters() #dom-vrdisplay-geteyeparameters Referenced in: Returns the current VREyeParameters for the given eye. The eye parameters MAY change at any time due to external factors, such as the user changing the IPD with hardware controls. As a result, it is recommended that these values be queried for each frame rather than cached.

Returns a VRPose describing the position, orientation, and acceleration of the VRDisplay that should be used when rendering the next frame of a scene. The User Agent MAY optionally use predictive techniques to estimate what the pose will be at the time that the next frame will be displayed to the user. The pose returned MUST NOT change until JavaScript has returned control to the browser.

Returns a VRPose describing the position, orientation, and acceleration of the VRDisplay at the time when the call was made. The User Agent SHOULD NOT use predictive techniques when constructing the pose.

Reset the pose for the VRDisplay , treating its current position and orientation as the "origin/zero" values. Future poses returned from getPose() and getImmediatePose() will describe positions relative to the VRDisplay ‘s position when resetPose() was last called and will treat the display’s yaw when resetPose() was last called as the forward orientation. The VRDisplay ‘s reported roll and pitch do not change when resetPose() is called as they are relative to gravity. Calling resetPose() may change the sittingToStandingTransform matrix of the VRStageParameters .

requestAnimationFrame() #dom-vrdisplay-requestanimationframe Referenced in: Functionally equivalent to window.requestAnimationFrame when the VRDisplay is not presenting. When the VRDisplay is presenting the callback is called at the native refresh rate of the VRDisplay .

cancelAnimationFrame() #dom-vrdisplay-cancelanimationframe Referenced in: Passing the value returned by requestAnimationFrame() to will unregister the callback.

Begins presenting the contents of the specified VRLayer array on the VRDisplay and fulfills the returned promise when presentation has begun. If canPresent is false the promise MUST be rejected. If the VRLayer array contains more than maxLayers elements the promise MUST be rejected. The user agent MAY reject the promise for any other reason. If the VRDisplay is already presenting when requestPresent() is called the VRDisplay SHOULD update the VRLayer list being presented. If a call to requestPresent() is rejected while the VRDisplay is already presenting the VRDisplay MUST end presentation.

exitPresent() #dom-vrdisplay-exitpresent Referenced in: Ends presentation to the VRDisplay and fulfills the returned promise when fully exited. If the VRDisplay is not presenting the promise MUST be rejected.

getLayers() #dom-vrdisplay-getlayers Referenced in: Returns an array with the VRLayer currently being presented. MUST return an empty array if the VRDisplay is not currently presenting. If the VRDisplay is presenting MUST return an array containing the VRLayer s last passed to requestPresent() .

submitFrame() #dom-vrdisplay-submitframe Referenced in: Captures the current state of the VRLayer currently being presented and displays it on the VRDisplay . Optionally a VRPose can be provided to describe the pose used to render the VRLayer contents, which MAY be used by the user agent to manipulate the layer contents to improve percived latency. If no VRPose is provided the last pose returned by getPose() will be used.

2.2. VRLayer

The VRLayer interface is provided to a VRDisplay and presented in the HMD.

typedef (HTMLCanvasElement or          OffscreenCanvas) VRSource#typedefdef-vrsourceReferenced in:2.2. VRLayer;  dictionary VRLayer#dictdef-vrlayerReferenced in:2.1. VRDisplay (2)2.1.1. Attributes (2) (3) (4) (5) (6) (7)2.2. VRLayer3. Security Considerations {   VRSource? source#dom-vrlayer-sourceReferenced in:2.2.1. Attributes (2) (3)3. Security Considerations = null;    sequence<float>? leftBounds#dom-vrlayer-leftboundsReferenced in:2.2.1. Attributes (2) = null;   sequence<float>? rightBounds#dom-vrlayer-rightboundsReferenced in:2.2.1. Attributes (2) = null; };

2.2.1. Attributes

source The source attribute defines the canvas whose contents will be presented by the VRDisplay when VRDisplay . submitFrame() is called.

leftBounds The leftBounds attribute contains four values defining the texture bounds within the source canvas to present to the eye in UV space: 0 left offset of the bounds (0.0 – 1.0); 1 top offset of the bounds (0.0 – 1.0); 2 width of the bounds (0.0 – 1.0); [3] height of the bounds (0.0 – 1.0). The leftBounds MUST default to [0.0, 0.0, 0.5, 1.0] .

rightBounds The rightBounds attribute contains four values defining the texture bounds rectangle within the source canvas to present to the eye in UV space: 0 left offset of the bounds (0.0 – 1.0); 1 top offset of the bounds (0.0 – 1.0); 2 width of the bounds (0.0 – 1.0); [3] height of the bounds (0.0 – 1.0). The rightBounds MUST default to [0.5, 0.0, 0.5, 1.0] .

2.3. VRDisplayCapabilities

The VRDisplayCapabilities interface describes the capabilities of a VRDisplay . These are expected to be static per-device/per-user.

interface VRDisplayCapabilities#vrdisplaycapabilitiesReferenced in:2.1. VRDisplay2.1.1. Attributes2.3. VRDisplayCapabilities2.6.1. Attributes {   readonly attribute boolean hasPosition;   readonly attribute boolean hasOrientation;   readonly attribute boolean hasExternalDisplay;   readonly attribute boolean canPresent;   readonly attribute unsigned long maxLayers; };

2.3.1. Attributes

hasPosition #dom-vrlayer-hasposition Referenced in: The hasPosition attribute MUST return whether the VRDisplay is capable of tracking its position.

hasOrientation #dom-vrlayer-hasorientation Referenced in: The hasOrientation attribute MUST return whether the VRDisplay is capable of tracking its orientation.

hasExternalDisplay #dom-vrlayer-hasexternaldisplay Referenced in: The hasExternalDisplay attribute MUST return whether the VRDisplay is separate from the device’s primary display. If presenting VR content will obscure other content on the device, this should be false. When false, the application should not attempt to mirror VR content or update non-VR UI because that content will not be visible.

canPresent #dom-vrlayer-canpresent Referenced in: The canPresent attribute MUST return whether the VRDisplay is capable of presenting content to an HMD or similar device. Can be used to indicate "magic window" devices that are capable of 6DoF tracking but for which VRDisplay . requestPresent() is not meaningful. If false then calls to VRDisplay . requestPresent() should always fail, and VRDisplay . getEyeParameters() should return NULL.

maxLayers #dom-vrlayer-maxlayers Referenced in: Indicates the maximum length of the array that requestPresent() will accept. MUST be 1 if canPresent is true, 0 otherwise.

Note: Future revisions of this spec may allow multiple layers to enable more complex rendering effects such as compositing WebGL and DOM elements together. That functionality is not allowed by this revision of the spec.

2.4. VREye

enum VREye#enumdef-vreyeReferenced in:2.1. VRDisplay {   "left",   "right" };

2.5. VRFieldOfView

The VRFieldOfView interface represents a field of view, as given by 4 degrees describing the view from a center point.

interface VRFieldOfView#vrfieldofviewReferenced in:2.5. VRFieldOfView (2)2.7. VREyeParameters {   readonly attribute double upDegrees;   readonly attribute double rightDegrees;   readonly attribute double downDegrees;   readonly attribute double leftDegrees; };
The following code snippet creates a WebGL-compatible projection matrix from a VRFieldOfView .
function fieldOfViewToProjectionMatrix (fov, zNear, zFar) {   var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);   var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);   var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);   var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);   var xScale = 2.0 / (leftTan + rightTan);   var yScale = 2.0 / (upTan + downTan);    var out = new Float32Array(16);   out[0] = xScale;   out[1] = 0.0;   out[2] = 0.0;   out[3] = 0.0;   out[4] = 0.0;   out[5] = yScale;   out[6] = 0.0;   out[7] = 0.0;   out[8] = -((leftTan - rightTan) * xScale * 0.5);   out[9] = ((upTan - downTan) * yScale * 0.5);   out[10] = -(zNear + zFar) / (zFar - zNear);   out[11] = -1.0;   out[12] = 0.0;   out[13] = 0.0;   out[14] = -(2.0 * zFar * zNear) / (zFar - zNear);   out[15] = 0.0;    return out; }

2.6. VRPose

The VRPose interface represents a sensor’s state at a given timestamp.

interface VRPose#vrposeReferenced in:2.1. VRDisplay (2) (3)2.1.1. Attributes (2) (3) (4)2.6.1. Attributes {   readonly attribute DOMHighResTimeStamp timestamp;    readonly attribute Float32Array? position;   readonly attribute Float32Array? linearVelocity;   readonly attribute Float32Array? linearAcceleration;    readonly attribute Float32Array? orientation;   readonly attribute Float32Array? angularVelocity;   readonly attribute Float32Array? angularAcceleration; };

2.6.1. Attributes

timestamp #dom-vrpose-timestamp Referenced in: Monotonically increasing value that allows the author to determine if position state data been updated from the hardware. Since values are monotonically increasing, they can be compared to determine the ordering of updates, as newer values will always be greater than or equal to older values.

Position of the VRDisplay at timestamp as a 3D vector. Position is given in meters from an origin point, which is either the position the sensor was first read at or the position of the sensor at the point that resetPose() was last called. The coordinate system uses these axis definitions:

  • Positive X is to the user’s right.

  • Positive Y is up.

  • Positive Z is behind the user.

All positions are given relative to the identity orientation in sitting space. Transforming this point with VRStageParameters . sittingToStandingTransform converts this to standing space. MAY be NULL if the sensor is incapable of providing positional data. User agents MAY provide emulated position values through techniques such as neck modeling, but when doing so SHOULD report VRDisplayCapabilities . hasPosition as false. When not NULL MUST be a three-element array.

linearVelocity #dom-vrpose-linearvelocity Referenced in: Linear velocity of the sensor at timestamp meters per second. MAY be NULL if the sensor is incapable of providing linear velocity. When not NULL MUST be a three-element array.

linearAcceleration #dom-vrpose-linearacceleration Referenced in: Linear acceleration of the sensor at timestamp given in meters per second. MAY be NULL if the sensor is incapable of providing linear acceleration. When not NULL MUST be a three-element array.

orientation #dom-vrpose-orientation Referenced in: Orientation of the sensor at timestamp as a quaternion. The orientation yaw (rotation around the Y axis) is relative to the initial yaw of the sensor when it was first read or the yaw of the sensor at the point that resetPose() was last called. An orientation of {x: 0, y: 0, z: 0, w: 1} is considered to be "forward." MAY be NULL if the sensor is incapable of providing orientation data. When not NULL MUST be a four-element array.

angularVelocity #dom-vrpose-angularvelocity Referenced in: Angular velocity of the sensor at timestamp given in radians per second. MAY be NULL if the sensor is incapable of providing angular velocity. When not NULL MUST be a three-element array.

angularAcceleration #dom-vrpose-angularacceleration Referenced in: Angular acceleration of the sensor at timestamp given in radians per second. MAY be NULL if the sensor is incapable of providing angular acceleration. When not NULL MUST be a three-element array.

The following code snippet creates a WebGL-compatible matrix from a VRPose :
function poseToMatrix (pose) {     var out = new Float32Array(16);      // If the orientation or position are NULL, provide defaults.     var q = pose.orientation ? pose.orientation : [0, 0, 0, 1];     var v = pose.position ? pose.position : [0, 0, 0];      // Compute some values for the quaternion math.     var x2 = q[0] + q[0];     var y2 = q[1] + q[1];     var z2 = q[2] + q[2];      var xx = q[0] * x2;     var xy = q[0] * y2;     var xz = q[0] * z2;     var yy = q[1] * y2;     var yz = q[1] * z2;     var zz = q[2] * z2;     var wx = q[3] * x2;     var wy = q[3] * y2;     var wz = q[3] * z2;      out[0] = 1 - (yy + zz);     out[1] = xy + wz;     out[2] = xz - wy;     out[3] = 0;     out[4] = xy - wz;     out[5] = 1 - (xx + zz);     out[6] = yz + wx;     out[7] = 0;     out[8] = xz + wy;     out[9] = yz - wx;     out[10] = 1 - (xx + yy);     out[11] = 0;     out[12] = v[0];     out[13] = v[1];     out[14] = v[2];     out[15] = 1;      return out; }

2.7. VREyeParameters

The VREyeParameters interface represents all the information required to correctly render a scene for a given eye.

interface VREyeParameters#vreyeparametersReferenced in:2.1. VRDisplay2.1.1. Attributes2.7. VREyeParameters {   [Constant, Cached] readonly attribute Float32Array offset;    [Constant, Cached] readonly attribute VRFieldOfView fieldOfView;    [Constant, Cached] readonly attribute unsigned long renderWidth;   [Constant, Cached] readonly attribute unsigned long renderHeight; };

2.7.1. Attributes

offset #dom-vreyeparameters-offset Referenced in: Offset from the center point between the users eyes to the center of the eye in meters. This value SHOULD represent half of the user’s interpupillary distance (IPD), but MAY also represent the distance from the center point of the headset to the center point of the lens for the given eye. Values for the left eye MUST be negative; values for the right eye MUST be positive.

fieldOfView #dom-vreyeparameters-fieldofview Referenced in: The current field of view for the eye, as the user adjusts her headset IPD.

renderWidth #dom-vreyeparameters-renderwidth Referenced in: Describes the recommended render target width of each eye viewport, in pixels. If multiple eyes are rendered in a single render target, then the render target should be made large enough to fit both viewports. The renderWidth for the left eye and right eye MUST NOT overlap, and the renderWidth for the right eye MUST be to the right of the renderWidth for the left eye.

renderHeight #dom-vreyeparameters-renderheight Referenced in: Describes the recommended render target height of each eye viewport, in pixels. If multiple eyes are rendered in a single render target, then the render target should be made large enough to fit both viewports. The renderWidth for the left eye and right eye MUST NOT overlap, and the renderWidth for the right eye MUST be to the right of the renderWidth for the left eye.

Many HMDs will distort the rendered image to counteract undesired effects introduced by the headset optics. Because of this the optimal resolution of the canvas will often be larger than the HMD’s physical resolution to ensure that the final image presented to the user has a 1:1 pixel ratio at the center of the user’s view. The optimal canvas resolution can be calculated from the renderWidth and renderHeight for both eyes as follows:
var leftEye = vrDisplay.getEyeParameters("left"); var rightEye = vrDisplay.getEyeParameters("right");  canvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2; canvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);

2.8. VRStageParameters

The VRStageParameters interface represents the values describing the the stage/play area for devices that support room-scale experiences.

interface VRStageParameters#vrstageparametersReferenced in:2.1. VRDisplay2.1.1. Attributes2.6.1. Attributes2.8. VRStageParameters {   readonly attribute Float32Array sittingToStandingTransform;    readonly attribute float sizeX;   readonly attribute float sizeZ; };

2.8.1. Attributes

The sittingToStandingTransform attribute is a 16-element array containing the components of a 4×4 transform matrix. This matrix transforms the sitting-space position returned by getPose() / getImmediatePose() to a standing-space position.

sizeX Width of the play-area bounds in meters. The bounds are defined as an axis-aligned rectangle on the floor. The center of the rectangle is at (0,0,0) in standing-space coordinates. These bounds are defined for safety purposes. Content should not require the user to move beyond these bounds; however, it is possible for the user to ignore the bounds resulting in position values outside of this rectangle.

sizeZ Depth of the play-area bounds in meters. The bounds are defined as an axis-aligned rectangle on the floor. The center of the rectangle is at (0,0,0) in standing-space coordinates. These bounds are defined for safety purposes. Content should not require the user to move beyond these bounds; however, it is possible for the user to ignore the bounds resulting in position values outside of this rectangle.

2.9. Navigator Interface extension

partial interface Navigator {   Promise<sequence<VRDisplay>> getVRDisplays();   readonly attribute sequence<VRDisplay> activeVRDisplays; };

2.9.1. Attributes

getVRDisplays() #navigator-getvrdisplays-attribute Referenced in: 2.9. Navigator Interface extension Return a Promise which resolves to a list of available VRDisplay s. Applications should iterate over the list and correlate devices that share displayId s to access the full capabilities of a device.

activeVRDisplays #navigator-activevrdisplays-attribute Referenced in: 2.9. Navigator Interface extension activeVRDisplays includes every VRDisplay that is currently presenting.

The following code finds the first available VRDisplay .
var vrDisplay;  navigator.getVRDisplays().then(function (displays) {   // Use the first display in the array if one is available. If multiple   // displays are present, you may want to present the user with a way to   // select which display to use.   if (displays.length > 0) {     vrDisplay = displays[0];   } });

2.10. Window Interface extension

partial interface Window {   attribute EventHandler onvrdisplayconnected;   attribute EventHandler onvrdisplaydisconnected;   attribute EventHandler onvrdisplaypresentchange; };

2.11. Gamepad Interface extension

partial interface Gamepad {   [Constant] readonly attribute unsigned long displayId; };

2.11.1. Attributes

displayId #gamepad-getvrdisplays-attribute Referenced in: 2.11. Gamepad Interface extension Return the displayId for the associated VRDisplay .

3. Security Considerations

While not directly affecting the API interface and Web IDL, the security model should maintains the user’s expectations of privacy on the Web:

  • The Gamepad API will be updated such that the gamepad inputs and HMD pose are available to only the focused tab.

  • Non-focused tabs are allowed to enumerate Gamepad s and VRDisplay s but will see last received state or default values.

  • All gamepads are assumed to be owned by the focused tabs, so can use them for secure inputs such as password fields.

  • Trusted UI elements presented by the browser would not be accessible by the GL context associated to the VRDisplay exposed to untrusted content.

  • Trusted UI would be rendered by chrome-only JavaScript code that has an independent GL context.

  • A "VR Compositor" runs asynchronously from content, responsible for compositing the trusted and untrusted content. If content is not performant or does not submit frames, the browser should be able to continue presenting a responsive front-end.

  • In the event that the content process terminates unexpectedly, the browser will not exit VR mode. The VR compositor will destroy the content layer while continuing to present the trusted UI elements of the browser.

  • The HMD pose and other VR inputs are only updated for the focused WebVR page. This can be implemented in the same manner as keyboard and mouse input.

  • Content does not need to request user permission to present to the VR HMD; however, any UI presented normally by the browser for 2D page content while loading a page or following links will be presented within the HMD to ensure that the user wishes to trust and visit the VR site.

  • If the user is uncomfortable in a VR world, she cannot look away from the display as it occupies her entire field of view. Instead the user is instructed to close her eyes and perform an action that does not require her vision to escape to a default page (such as pressing a reserved button or performing a gesture with motion controls).

  • To prevent CORS-related vulnerabilities, each page will see an independent instance of objects returned by the WebVR API, such as VRDisplay . Care must be taken to ensure that attributes such as VRLayer . source set by one page can not be read by another.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » WebVR spec 1.0

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址