mirror of
https://github.com/servo/servo.git
synced 2025-08-15 02:15:33 +01:00
Update web-platform-tests to revision 78f764c05c229883e87ad135c7153051a66e2851
This commit is contained in:
parent
55347aa39f
commit
bf84a079f9
1983 changed files with 58006 additions and 31437 deletions
|
@ -0,0 +1,32 @@
|
|||
// assert_equals can fail when comparing floats due to precision errors, so
|
||||
// use assert_approx_equals with this constant instead
|
||||
const FLOAT_EPSILON = 0.001;
|
||||
|
||||
// Identity matrix
|
||||
const IDENTITY_MATRIX = [1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1];
|
||||
|
||||
// A valid pose matrix for when we don't care about specific values
|
||||
const VALID_POSE_MATRIX = [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1];
|
||||
|
||||
const VALID_PROJECTION_MATRIX =
|
||||
[1, 0, 0, 0, 0, 1, 0, 0, 3, 2, -1, -1, 0, 0, -0.2, 0];
|
||||
|
||||
const VALID_VIEW_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4, 3, 2, 1];
|
||||
|
||||
// A valid VRPose for when we want the HMD to report being at the origin
|
||||
const ORIGIN_POSE = IDENTITY_MATRIX;
|
||||
|
||||
// A valid input grip matrix for when we don't care about specific values
|
||||
const VALID_GRIP = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4, 3, 2, 1];
|
||||
|
||||
// A valid input pointer offset for when we don't care about specific values
|
||||
const VALID_POINTER_OFFSET = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1];
|
||||
|
||||
const VALID_GRIP_WITH_POINTER_OFFSET =
|
||||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4, 3, 3, 1];
|
||||
|
||||
const VALID_STAGE_TRANSFORM =
|
||||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1.0, 1.65, -1.0, 1];
|
|
@ -0,0 +1,31 @@
|
|||
// Utility assert functions.
|
||||
// Relies on resources/testharness.js to be included before this file.
|
||||
|
||||
// |p1|, |p2| - objects with x, y, z, w components that are floating point numbers
|
||||
// |epsilon| - float specifying precision
|
||||
// |prefix| - string used as a prefix for logging
|
||||
let assert_point_approx_equals = function(p1, p2, epsilon, prefix = "") {
|
||||
assert_approx_equals(p1.x, p2.x, epsilon, prefix + "xs must match");
|
||||
assert_approx_equals(p1.y, p2.y, epsilon, prefix + "ys must match");
|
||||
assert_approx_equals(p1.z, p2.z, epsilon, prefix + "zs must match");
|
||||
assert_approx_equals(p1.w, p2.w, epsilon, prefix + "ws must match");
|
||||
};
|
||||
|
||||
// |m1|, |m2| - arrays of floating point numbers
|
||||
// |epsilon| - float specifying precision
|
||||
// |prefix| - string used as a prefix for logging
|
||||
let assert_matrix_approx_equals = function(m1, m2, epsilon, prefix = "") {
|
||||
assert_equals(m1.length, m2.length, prefix + "Matrix lengths should match");
|
||||
for(var i = 0; i < m1.length; ++i) {
|
||||
assert_approx_equals(m1[i], m2[i], epsilon, prefix + "Component number " + i + " should match");
|
||||
}
|
||||
}
|
||||
|
||||
// |r1|, |r2| - XRRay objects
|
||||
// |epsilon| - float specifying precision
|
||||
// |prefix| - string used as a prefix for logging
|
||||
let assert_ray_approx_equals = function(r1, r2, epsilon, prefix = "") {
|
||||
assert_point_approx_equals(r1.origin, r2.origin, epsilon, prefix + "origin:");
|
||||
assert_point_approx_equals(r1.direction, r2.direction, epsilon, prefix + "direction:");
|
||||
assert_matrix_approx_equals(r1.matrix, r2.matrix, epsilon, prefix + "matrix:");
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// assert_equals can fail when comparing floats due to precision errors, so
|
||||
// use assert_approx_equals with this constant instead
|
||||
const FLOAT_EPSILON = 0.001;
|
||||
|
||||
// Identity matrix
|
||||
const IDENTITY_MATRIX = [1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1];
|
||||
|
||||
// A valid pose matrix for when we don't care about specific values
|
||||
const VALID_POSE_MATRIX = [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1];
|
||||
|
||||
const VALID_PROJECTION_MATRIX =
|
||||
[1, 0, 0, 0, 0, 1, 0, 0, 3, 2, -1, -1, 0, 0, -0.2, 0];
|
||||
|
||||
const VALID_VIEW_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4, 3, 2, 1];
|
||||
|
||||
// A valid VRPose for when we want the HMD to report being at the origin
|
||||
const ORIGIN_POSE = IDENTITY_MATRIX;
|
||||
|
||||
// A valid input grip matrix for when we don't care about specific values
|
||||
const VALID_GRIP = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4, 3, 2, 1];
|
||||
|
||||
// A valid input pointer offset for when we don't care about specific values
|
||||
const VALID_POINTER_OFFSET = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1];
|
||||
|
||||
const VALID_GRIP_WITH_POINTER_OFFSET =
|
||||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4, 3, 3, 1];
|
||||
|
||||
const VALID_STAGE_TRANSFORM =
|
||||
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1.0, 1.65, -1.0, 1];
|
|
@ -54,7 +54,9 @@ function xr_session_promise_test(
|
|||
// Session must have a baseLayer or frame requests
|
||||
// will be ignored.
|
||||
session.updateRenderState({
|
||||
baseLayer: new XRWebGLLayer(session, gl) });
|
||||
baseLayer: new XRWebGLLayer(session, gl),
|
||||
outputContext: getOutputContext()
|
||||
});
|
||||
resolve(func(session, testDeviceController, t));
|
||||
})
|
||||
.catch((err) => {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// Utility assert functions.
|
||||
// Relies on resources/testharness.js to be included before this file.
|
||||
|
||||
// |p1|, |p2| - objects with x, y, z, w components that are floating point numbers
|
||||
// |epsilon| - float specifying precision
|
||||
// |prefix| - string used as a prefix for logging
|
||||
let assert_point_approx_equals = function(p1, p2, epsilon, prefix = "") {
|
||||
assert_approx_equals(p1.x, p2.x, epsilon, prefix + "xs must match");
|
||||
assert_approx_equals(p1.y, p2.y, epsilon, prefix + "ys must match");
|
||||
assert_approx_equals(p1.z, p2.z, epsilon, prefix + "zs must match");
|
||||
assert_approx_equals(p1.w, p2.w, epsilon, prefix + "ws must match");
|
||||
};
|
||||
|
||||
// |m1|, |m2| - arrays of floating point numbers
|
||||
// |epsilon| - float specifying precision
|
||||
// |prefix| - string used as a prefix for logging
|
||||
let assert_matrix_approx_equals = function(m1, m2, epsilon, prefix = "") {
|
||||
assert_equals(m1.length, m2.length, prefix + "Matrix lengths should match");
|
||||
for(var i = 0; i < m1.length; ++i) {
|
||||
assert_approx_equals(m1[i], m2[i], epsilon, prefix + "Component number " + i + " should match");
|
||||
}
|
||||
}
|
||||
|
||||
// |r1|, |r2| - XRRay objects
|
||||
// |epsilon| - float specifying precision
|
||||
// |prefix| - string used as a prefix for logging
|
||||
let assert_ray_approx_equals = function(r1, r2, epsilon, prefix = "") {
|
||||
assert_point_approx_equals(r1.origin, r2.origin, epsilon, prefix + "origin:");
|
||||
assert_point_approx_equals(r1.direction, r2.direction, epsilon, prefix + "direction:");
|
||||
assert_matrix_approx_equals(r1.matrix, r2.matrix, epsilon, prefix + "matrix:");
|
||||
}
|
|
@ -9,8 +9,7 @@
|
|||
(t) => {
|
||||
return XRTest.simulateDeviceConnection({ supportsImmersive:false })
|
||||
.then( (controller) => navigator.xr.requestSession({
|
||||
mode: 'inline',
|
||||
outputContext: getOutputContext()
|
||||
mode: 'inline'
|
||||
}))
|
||||
.then( (session) => { assert_not_equals(session, null); });
|
||||
});
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/test-constants.js"></script>
|
||||
<script src="resources/webxr_util.js"></script>
|
||||
<script src="resources/xr-test-asserts.js"></script>
|
||||
<canvas></canvas>
|
||||
|
||||
<script>
|
||||
|
||||
let immersiveTestName = "XRFrame.getPose works for immersive sessions";
|
||||
let nonImmersiveTestName = "XRFrame.getPose works for non-immersive sessions";
|
||||
|
||||
let fakeDeviceInitParams = { supportsImmersive:true };
|
||||
let immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
|
||||
|
||||
let testFunction = function(session, fakeDeviceController, t) {
|
||||
// Need to have a valid pose or input events don't process.
|
||||
fakeDeviceController.setXRPresentationFrameData(VALID_POSE_MATRIX, [{
|
||||
eye:"left",
|
||||
projectionMatrix: VALID_PROJECTION_MATRIX,
|
||||
viewMatrix: VALID_VIEW_MATRIX
|
||||
}, {
|
||||
eye:"right",
|
||||
projectionMatrix: VALID_PROJECTION_MATRIX,
|
||||
viewMatrix: VALID_VIEW_MATRIX
|
||||
}]);
|
||||
|
||||
return Promise.all([
|
||||
session.requestReferenceSpace({ type: "stationary", subtype: "eye-level" }),
|
||||
session.requestReferenceSpace({ type: "stationary", subtype: "eye-level" })
|
||||
]).then((spaces) => new Promise((resolve) => {
|
||||
function onFrame(time, xrFrame) {
|
||||
const radians = Math.PI / 2.0; // 90 degrees
|
||||
|
||||
// Both eye-level spaces start out with originOffset = identity matrix.
|
||||
let space1 = spaces[0];
|
||||
let space2 = spaces[1];
|
||||
|
||||
// Rotate 90 degrees about x axis, then move 1 meter along y axis.
|
||||
space1.originOffset = new XRRigidTransform(
|
||||
DOMPointReadOnly.fromPoint({
|
||||
x : 0,
|
||||
y : 1,
|
||||
z : 0,
|
||||
w : 0
|
||||
}),
|
||||
DOMPointReadOnly.fromPoint({
|
||||
x : Math.sin(radians / 2),
|
||||
y : 0,
|
||||
z : 0,
|
||||
w : Math.cos(radians / 2)
|
||||
})
|
||||
);
|
||||
|
||||
// Rotate 90 degrees about z axis, then move 1 meter along x axis.
|
||||
space2.originOffset = new XRRigidTransform(
|
||||
DOMPointReadOnly.fromPoint({
|
||||
x : 1,
|
||||
y : 0,
|
||||
z : 0,
|
||||
w : 0
|
||||
}),
|
||||
DOMPointReadOnly.fromPoint({
|
||||
x : 0,
|
||||
y : 0,
|
||||
z : Math.sin(radians / 2),
|
||||
w : Math.cos(radians / 2)
|
||||
})
|
||||
);
|
||||
|
||||
let space1_from_space2 = xrFrame.getPose(space1, space2);
|
||||
const EXPECTED_POSE_MATRIX = [
|
||||
0, 0, -1, 0, // 1st column
|
||||
-1, 0, 0, 0, // 2nd column
|
||||
0, 1, 0, 0, // 3rd column
|
||||
1, 0, 1, 1 // 4th column
|
||||
];
|
||||
assert_matrix_approx_equals(space1_from_space2.transform.matrix, EXPECTED_POSE_MATRIX, FLOAT_EPSILON);
|
||||
|
||||
// Finished test.
|
||||
resolve();
|
||||
}
|
||||
|
||||
session.requestAnimationFrame(onFrame);
|
||||
}));
|
||||
};
|
||||
|
||||
xr_session_promise_test(immersiveTestName, testFunction,
|
||||
fakeDeviceInitParams, immersiveSessionOptions);
|
||||
xr_session_promise_test(nonImmersiveTestName, testFunction,
|
||||
fakeDeviceInitParams, nonImmersiveSessionOptions);
|
||||
|
||||
</script>
|
145
tests/wpt/web-platform-tests/webxr/xrRay_constructor.https.html
Normal file
145
tests/wpt/web-platform-tests/webxr/xrRay_constructor.https.html
Normal file
|
@ -0,0 +1,145 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/webxr_test_constants.js"></script>
|
||||
<script src="resources/webxr_test_asserts.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
let constructor_test_name = "XRRay constructors work";
|
||||
|
||||
let constructor_tests = function() {
|
||||
// Constructor tests for XRRay.
|
||||
// Spec: https://immersive-web.github.io/webxr/#xrray-interface
|
||||
|
||||
//
|
||||
// Constructor 1 - from origin and direction
|
||||
//
|
||||
|
||||
{
|
||||
// Check defaults - should be 0,0,0,1 for origin and 0,0,-1,0 for direction,
|
||||
// identity matrix for the transform:
|
||||
let xrRay = new XRRay();
|
||||
assert_point_approx_equals(
|
||||
xrRay.origin, {x : 0.0, y : 0.0, z : 0.0, w : 1.0},
|
||||
FLOAT_EPSILON, "origin-default:");
|
||||
assert_point_approx_equals(
|
||||
xrRay.direction, {x : 0.0, y : 0.0, z : -1.0, w : 0.0},
|
||||
FLOAT_EPSILON, "direction-default:");
|
||||
assert_matrix_approx_equals(
|
||||
xrRay.matrix, IDENTITY_MATRIX,
|
||||
FLOAT_EPSILON, "matrix-default:");
|
||||
}
|
||||
|
||||
{
|
||||
// Check custom value for origin, default for direction:
|
||||
let originDict = {x : 11.0, y : 12.0, z : 13.0, w : 1.0};
|
||||
let xrRay2 = new XRRay(DOMPoint.fromPoint(originDict));
|
||||
let xrRay3 = new XRRay(DOMPointReadOnly.fromPoint(originDict));
|
||||
let matrix1 = [ 1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
11, 12, 13, 1];
|
||||
|
||||
assert_point_approx_equals(
|
||||
xrRay2.origin, originDict,
|
||||
FLOAT_EPSILON, "origin-custom-direction-default:");
|
||||
assert_point_approx_equals(
|
||||
xrRay2.direction, {x : 0.0, y : 0.0, z : -1.0, w : 0.0},
|
||||
FLOAT_EPSILON, "direction-custom-direction-default:");
|
||||
assert_matrix_approx_equals(
|
||||
xrRay2.matrix, matrix1,
|
||||
FLOAT_EPSILON, "matrix-custom-direction-default:");
|
||||
|
||||
assert_ray_approx_equals(xrRay2, xrRay3, FLOAT_EPSILON, "ray2-ray3-direction-default:");
|
||||
}
|
||||
|
||||
{
|
||||
// Check custom values - ray rotated from -Z onto +X,
|
||||
// not placed at origin:
|
||||
// - from DOMPoint
|
||||
// - from DOMPointReadOnly
|
||||
let originDict = {x : 10.0, y : 10.0, z : 10.0, w : 1.0};
|
||||
let directionDict = {x : 10.0, y : 0.0, z : 0.0, w : 0.0};
|
||||
let directionNorm = {x : 1.0, y : 0.0, z : 0.0, w : 0.0};
|
||||
// column-major
|
||||
let matrix1 = [ 0, 0, 1, 0,
|
||||
0, 1, 0, 0,
|
||||
-1, 0, 0, 0,
|
||||
10, 10, 10, 1];
|
||||
|
||||
let xrRay2 = new XRRay(
|
||||
DOMPoint.fromPoint(originDict),
|
||||
DOMPoint.fromPoint(directionDict));
|
||||
|
||||
let xrRay3 = new XRRay(
|
||||
DOMPointReadOnly.fromPoint(originDict),
|
||||
DOMPointReadOnly.fromPoint(directionDict));
|
||||
|
||||
assert_point_approx_equals(
|
||||
xrRay2.origin, originDict,
|
||||
FLOAT_EPSILON, "origin-custom:");
|
||||
assert_point_approx_equals(
|
||||
xrRay2.direction, directionNorm,
|
||||
FLOAT_EPSILON, "direction-custom:");
|
||||
assert_matrix_approx_equals(
|
||||
xrRay2.matrix, matrix1,
|
||||
FLOAT_EPSILON, "matrix-custom:");
|
||||
|
||||
assert_ray_approx_equals(xrRay2, xrRay3, FLOAT_EPSILON, "ray2-ray3:");
|
||||
}
|
||||
|
||||
{
|
||||
// Check that we don't crash on direction too close to 0,0,0:
|
||||
let originDict = {x : 10.0, y : 10.0, z : 10.0, w : 1.0};
|
||||
let directionDict = {x : 0.0, y : 0.0, z : 0.0, w : 0.0};
|
||||
|
||||
let xrRay = new XRRay(
|
||||
DOMPoint.fromPoint(originDict),
|
||||
DOMPoint.fromPoint(directionDict));
|
||||
|
||||
assert_point_approx_equals(
|
||||
xrRay.origin, originDict,
|
||||
FLOAT_EPSILON, "origin-custom-direction-zero:");
|
||||
|
||||
// cannot validate direction's & matrix's values w/o making it depend on current
|
||||
// implementation, just check that they're not null
|
||||
assert_not_equals(xrRay.direction, null, "origin-custom-direction-zero:direction should not be null");
|
||||
assert_not_equals(xrRay.matrix, null, "origin-custom-direction-zero:matrix should not be null");
|
||||
}
|
||||
|
||||
//
|
||||
// Constructor 2 - from rigid transform.
|
||||
//
|
||||
|
||||
{
|
||||
// Not placed at origin, ray rotated by 135 degrees around Y:
|
||||
let originDict = {x : 10.0, y : 10.0, z : 10.0, w : 1.0};
|
||||
let directionQuaternionDict = { x : 0, y : 0.9239, z : 0, w : 0.3827 };
|
||||
let directionNorm2 = { x : -0.707, y : 0.0, z : 0.707, w : 0.0 };
|
||||
let matrix2 = [-0.707, 0, -0.707, 0,
|
||||
0., 1, 0, 0,
|
||||
0.707, 0, -0.707, 0,
|
||||
10., 10, 10., 1];
|
||||
|
||||
let xrRay4 = new XRRay(
|
||||
new XRRigidTransform(
|
||||
DOMPoint.fromPoint(originDict),
|
||||
DOMPoint.fromPoint(directionQuaternionDict)));
|
||||
|
||||
assert_point_approx_equals(
|
||||
xrRay4.origin, originDict,
|
||||
FLOAT_EPSILON, "origin-custom-rigid:");
|
||||
assert_point_approx_equals(
|
||||
xrRay4.direction, directionNorm2,
|
||||
FLOAT_EPSILON, "direction-custom-rigid:");
|
||||
|
||||
assert_matrix_approx_equals(
|
||||
xrRay4.matrix, matrix2,
|
||||
FLOAT_EPSILON, "matrix-custom-rigid:");
|
||||
}
|
||||
};
|
||||
|
||||
test(constructor_tests, constructor_test_name);
|
||||
|
||||
</script>
|
123
tests/wpt/web-platform-tests/webxr/xrRay_matrix.https.html
Normal file
123
tests/wpt/web-platform-tests/webxr/xrRay_matrix.https.html
Normal file
|
@ -0,0 +1,123 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/webxr_test_constants.js"></script>
|
||||
<script src="resources/webxr_test_asserts.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
// |matrix| - Float32Array, |input| - point-like dict (must have x, y, z, w)
|
||||
let transform_point = function (matrix, input) {
|
||||
return {
|
||||
x : matrix[0] * input.x + matrix[4] * input.y + matrix[8] * input.z + matrix[12] * input.w,
|
||||
y : matrix[1] * input.x + matrix[5] * input.y + matrix[9] * input.z + matrix[13] * input.w,
|
||||
z : matrix[2] * input.x + matrix[6] * input.y + matrix[10] * input.z + matrix[14] * input.w,
|
||||
w : matrix[3] * input.x + matrix[7] * input.y + matrix[11] * input.z + matrix[15] * input.w,
|
||||
};
|
||||
}
|
||||
|
||||
// |point| - point-like dict (must have x, y, z, w)
|
||||
let normalize_perspective = function(point) {
|
||||
if(point.w == 0 || point.w == 1) return point;
|
||||
|
||||
return {
|
||||
x : point.x / point.w,
|
||||
y : point.y / point.w,
|
||||
z : point.z / point.w,
|
||||
w : 1
|
||||
};
|
||||
}
|
||||
|
||||
let matrix_tests_name = "XRRay matrix works";
|
||||
|
||||
let matrix_tests = function() {
|
||||
// Matrix tests for XRRay.
|
||||
// Spec: https://immersive-web.github.io/webxr/#xrray-interface
|
||||
|
||||
const initialOrigin = {x : 0, y : 0, z : 0, w : 1};
|
||||
const initialDirection = {x : 0, y : 0, z : -1, w : 0};
|
||||
|
||||
// Test 1. Simple translation and rotation.
|
||||
{
|
||||
let originDict = {x : 10.0, y : 10.0, z : 10.0, w : 1.0};
|
||||
let directionDict = {x : 10.0, y : 0.0, z : 0.0, w : 0.0};
|
||||
let directionNorm = {x : 1.0, y : 0.0, z : 0.0, w : 0.0};
|
||||
let xrRay = new XRRay(
|
||||
DOMPoint.fromPoint(originDict),
|
||||
DOMPoint.fromPoint(directionDict));
|
||||
|
||||
let transformedOrigin = normalize_perspective(transform_point(xrRay.matrix, initialOrigin));
|
||||
let transformedDirection = normalize_perspective(transform_point(xrRay.matrix, initialDirection));
|
||||
|
||||
assert_point_approx_equals(
|
||||
originDict, transformedOrigin,
|
||||
FLOAT_EPSILON, "origin-test1:");
|
||||
assert_point_approx_equals(
|
||||
directionNorm, transformedDirection,
|
||||
FLOAT_EPSILON, "direction-test1:");
|
||||
}
|
||||
|
||||
// Test 2. Co-linear direction - rotation by 180 deg.
|
||||
{
|
||||
let originDict = {x : 10.0, y : 10.0, z : 10.0, w : 1.0};
|
||||
let directionDict = {x : 0.0, y : 0.0, z : 1.0, w : 0.0};
|
||||
let directionNorm = {x : 0.0, y : 0.0, z : 1.0, w : 0.0};
|
||||
let xrRay = new XRRay(
|
||||
DOMPoint.fromPoint(originDict),
|
||||
DOMPoint.fromPoint(directionDict));
|
||||
|
||||
let transformedOrigin = normalize_perspective(transform_point(xrRay.matrix, initialOrigin));
|
||||
let transformedDirection = normalize_perspective(transform_point(xrRay.matrix, initialDirection));
|
||||
|
||||
assert_point_approx_equals(
|
||||
originDict, transformedOrigin,
|
||||
FLOAT_EPSILON, "origin-test2:");
|
||||
assert_point_approx_equals(
|
||||
directionNorm, transformedDirection,
|
||||
FLOAT_EPSILON, "direction-test2:");
|
||||
}
|
||||
|
||||
// Test 3. No translation.
|
||||
{
|
||||
let originDict = {x : 0.0, y : 0.0, z : 0.0, w : 1.0};
|
||||
let directionDict = {x : 10.0, y : 0.0, z : 0.0, w : 0.0};
|
||||
let directionNorm = {x : 1.0, y : 0.0, z : 0.0, w : 0.0};
|
||||
let xrRay = new XRRay(
|
||||
DOMPoint.fromPoint(originDict),
|
||||
DOMPoint.fromPoint(directionDict));
|
||||
|
||||
let transformedOrigin = normalize_perspective(transform_point(xrRay.matrix, initialOrigin));
|
||||
let transformedDirection = normalize_perspective(transform_point(xrRay.matrix, initialDirection));
|
||||
|
||||
assert_point_approx_equals(
|
||||
originDict, transformedOrigin,
|
||||
FLOAT_EPSILON, "origin-test3:");
|
||||
assert_point_approx_equals(
|
||||
directionNorm, transformedDirection,
|
||||
FLOAT_EPSILON, "direction-test3:");
|
||||
}
|
||||
|
||||
// Test 4. No rotation.
|
||||
{
|
||||
let originDict = {x : 10.0, y : 10.0, z : 10.0, w : 1.0};
|
||||
let directionDict = {x : 0.0, y : 0.0, z : -1.0, w : 0.0};
|
||||
let directionNorm = {x : 0.0, y : 0.0, z : -1.0, w : 0.0};
|
||||
let xrRay = new XRRay(
|
||||
DOMPoint.fromPoint(originDict),
|
||||
DOMPoint.fromPoint(directionDict));
|
||||
|
||||
let transformedOrigin = normalize_perspective(transform_point(xrRay.matrix, initialOrigin));
|
||||
let transformedDirection = normalize_perspective(transform_point(xrRay.matrix, initialDirection));
|
||||
|
||||
assert_point_approx_equals(
|
||||
originDict, transformedOrigin,
|
||||
FLOAT_EPSILON, "origin-test4:");
|
||||
assert_point_approx_equals(
|
||||
directionNorm, transformedDirection,
|
||||
FLOAT_EPSILON, "direction-test4:");
|
||||
}
|
||||
};
|
||||
|
||||
test(matrix_tests, matrix_tests_name);
|
||||
|
||||
</script>
|
|
@ -0,0 +1,113 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/webxr_util.js"></script>
|
||||
<script src="resources/webxr_test_constants.js"></script>
|
||||
<canvas id="webgl-canvas"></canvas>
|
||||
|
||||
<script>
|
||||
|
||||
let testName = "XRRigidTransform constructor works";
|
||||
let fakeDeviceInitParams = { supportsImmersive: true };
|
||||
let requestSessionOptions = { mode: 'immersive-vr' };
|
||||
|
||||
let testFunction =
|
||||
(session, fakeDeviceController, t) => new Promise((resolve, reject) => {
|
||||
let coordDict = function(coords) {
|
||||
let tempDict = {
|
||||
x : coords[0],
|
||||
y : coords[1],
|
||||
z : coords[2]
|
||||
}
|
||||
|
||||
if (coords.length >= 4) {
|
||||
tempDict["w"] = coords[3];
|
||||
}
|
||||
|
||||
return tempDict;
|
||||
};
|
||||
|
||||
let createDOMPoint = function(coords) {
|
||||
return DOMPoint.fromPoint(coordDict(coords));
|
||||
};
|
||||
|
||||
let createDOMPointReadOnly = function(coords) {
|
||||
return DOMPointReadOnly.fromPoint(coordDict(coords));
|
||||
};
|
||||
|
||||
let quaternionLength = function(point) {
|
||||
return Math.sqrt(
|
||||
(point.x * point.x) +
|
||||
(point.y * point.y) +
|
||||
(point.z * point.z) +
|
||||
(point.w * point.w));
|
||||
};
|
||||
|
||||
let checkDOMPoint = function(point, x, y, z, w) {
|
||||
t.step(() => {
|
||||
assert_approx_equals(point.x, x, FLOAT_EPSILON);
|
||||
assert_approx_equals(point.y, y, FLOAT_EPSILON);
|
||||
assert_approx_equals(point.z, z, FLOAT_EPSILON);
|
||||
assert_approx_equals(point.w, w, FLOAT_EPSILON);
|
||||
});
|
||||
};
|
||||
|
||||
let checkTransform = function(transformObj) {
|
||||
t.step(() => {
|
||||
assert_not_equals(transformObj, null);
|
||||
assert_not_equals(transformObj.position, null);
|
||||
assert_not_equals(transformObj.orientation, null);
|
||||
assert_not_equals(transformObj.matrix, null);
|
||||
assert_equals(transformObj.matrix.length, 16);
|
||||
});
|
||||
};
|
||||
|
||||
// test creating transform with specified position and orientation
|
||||
// make sure that orientation was normalized to have length = 1.0
|
||||
let transform = new XRRigidTransform(
|
||||
createDOMPoint([1.0, 2.0, 3.0]),
|
||||
createDOMPoint([1.1, 2.1, 3.1, 1.0]));
|
||||
checkTransform(transform);
|
||||
checkDOMPoint(transform.position, 1.0, 2.0, 3.0, 1.0);
|
||||
assert_approx_equals(quaternionLength(transform.orientation), 1.0, FLOAT_EPSILON);
|
||||
|
||||
// test creating identity transform
|
||||
let identity = new XRRigidTransform();
|
||||
checkTransform(identity);
|
||||
checkDOMPoint(identity.position, 0.0, 0.0, 0.0, 1.0);
|
||||
checkDOMPoint(identity.orientation, 0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// test creating transform with quaternion of length 0
|
||||
// constructor should not crash
|
||||
let zeroLength = new XRRigidTransform(
|
||||
createDOMPoint([1.0, 2.0, 3.0]),
|
||||
createDOMPoint([0.0, 0.0, 0.0, 0.0]));
|
||||
checkTransform(zeroLength);
|
||||
|
||||
// create transform with only position specified
|
||||
transform = new XRRigidTransform(createDOMPoint([1.0, 2.0, 3.0]));
|
||||
checkTransform(transform);
|
||||
|
||||
// create transform with only orientation specified
|
||||
transform = new XRRigidTransform(undefined, createDOMPoint([1.1, 2.1, 3.1, 1.0]));
|
||||
checkTransform(transform);
|
||||
|
||||
// create transform with DOMPointReadOnly
|
||||
transform = new XRRigidTransform(
|
||||
createDOMPointReadOnly([1.0, 2.0, 3.0]),
|
||||
createDOMPointReadOnly([1.1, 2.1, 3.1, 1.0]));
|
||||
checkTransform(transform);
|
||||
|
||||
// create transform with dictionary
|
||||
transform = new XRRigidTransform(
|
||||
coordDict([1.0, 2.0, 3.0]),
|
||||
coordDict([1.1, 2.1, 3.1, 1.0]));
|
||||
checkTransform(transform);
|
||||
|
||||
resolve();
|
||||
});
|
||||
|
||||
xr_session_promise_test(testName, testFunction, fakeDeviceInitParams,
|
||||
requestSessionOptions);
|
||||
|
||||
</script>
|
|
@ -14,7 +14,7 @@
|
|||
let fakeDeviceInitParams = { supportsImmersive:true };
|
||||
|
||||
let immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
|
||||
let nonImmersiveSessionOptions = { mode: 'inline' };
|
||||
|
||||
let testFunction = (session) => new Promise((resolve, reject) => {
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
let fakeDeviceInitParams = { supportsImmersive:true };
|
||||
|
||||
let immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
|
||||
let nonImmersiveSessionOptions = { mode: 'inline' };
|
||||
|
||||
let testFunction = (testSession) => new Promise((resolve) => {
|
||||
let counter = 0;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
const fakeDeviceInitParams = { supportsImmersive:true };
|
||||
|
||||
const immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
const nonImmersiveSessionOptions = { outputContext: getOutputContext() };
|
||||
const nonImmersiveSessionOptions = { mode: 'inline' };
|
||||
|
||||
let testFunction = function(session, testDeviceController, t) {
|
||||
let eventWatcher = new EventWatcher(t, session, ["end", "watcherdone"]);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
let fakeDeviceInitParams = { supportsImmersive: true };
|
||||
|
||||
let immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
let inlineSessionOptions = { outputContext: getOutputContext() };
|
||||
let inlineSessionOptions = { mode: 'inline' };
|
||||
|
||||
const identityMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
let fakeDeviceInitParams = { supportsImmersive:true };
|
||||
|
||||
let immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
|
||||
let nonImmersiveSessionOptions = { mode: 'inline' };
|
||||
|
||||
let testFunction = (testSession) => new Promise((resolve) => {
|
||||
function onFrame(time, xrFrame) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
let fakeDeviceInitParams = { supportsImmersive: true };
|
||||
|
||||
let immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
|
||||
let nonImmersiveSessionOptions = { mode: 'inline' };
|
||||
|
||||
// Valid matrices for when we don't care about specific values
|
||||
const validPoseMatrix = [0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1];
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
let fakeDeviceInitParams = { supportsImmersive: true };
|
||||
|
||||
let immersiveSessionOptions = { mode: 'immersive-vr' };
|
||||
let nonImmersiveSessionOptions = { outputContext: getOutputContext() };
|
||||
let nonImmersiveSessionOptions = { mode: 'inline' };
|
||||
|
||||
let testFunction = function(session, fakeDeviceController, t) {
|
||||
return promise_rejects(t, new TypeError(), session.requestReferenceSpace({ type: "foo" }))
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<!DOCTYPE html>
|
||||
<body>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<script src="resources/webxr_util.js"></script>
|
||||
<script>
|
||||
xr_promise_test(
|
||||
"Ensure that XRPresentationContexts are properly transfered between session",
|
||||
(t) => {
|
||||
return XRTest.simulateDeviceConnection({ supportsImmersive:false })
|
||||
.then( (controller) => {
|
||||
Promise.all([
|
||||
navigator.xr.requestSession({ mode: 'inline'}),
|
||||
navigator.xr.requestSession({ mode: 'inline'})
|
||||
]).then((sessions) => {
|
||||
assert_not_equals(sessions[0], null);
|
||||
assert_not_equals(sessions[1], null);
|
||||
|
||||
let outputContext = getOutputContext();
|
||||
|
||||
sessions[0].updateRenderState({
|
||||
baseLayer: new XRWebGLLayer(session, gl),
|
||||
outputContext: outputContext
|
||||
});
|
||||
|
||||
sessions[0].requestAnimationFrame((time, xrFrame) => {
|
||||
sessions[1].updateRenderState({
|
||||
baseLayer: new XRWebGLLayer(session, gl),
|
||||
outputContext: outputContext
|
||||
});
|
||||
|
||||
// outputContext reassignment should not happen until the next frame is processed.
|
||||
assert_equals(sessions[0].renderState.outputContext, outputContext);
|
||||
assert_equals(sessions[1].renderState.outputContext, null);
|
||||
|
||||
sessions[1].requestAnimationFrame((time, xrFrame) => {
|
||||
// Ensure the outputContext was properly reassigned from one context to the other.
|
||||
assert_equals(sessions[0].renderState.outputContext, null);
|
||||
assert_equals(sessions[1].renderState.outputContext, outputContext);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue