webxr_test_constants.js (5745B)
1 // assert_equals can fail when comparing floats due to precision errors, so 2 // use assert_approx_equals with this constant instead 3 const FLOAT_EPSILON = 0.001; 4 5 // Identity matrix 6 const IDENTITY_MATRIX = [1, 0, 0, 0, 7 0, 1, 0, 0, 8 0, 0, 1, 0, 9 0, 0, 0, 1]; 10 11 const IDENTITY_TRANSFORM = { 12 position: [0, 0, 0], 13 orientation: [0, 0, 0, 1], 14 }; 15 16 // A valid pose matrix/transform for when we don't care about specific values 17 // Note that these two should be identical, just different representations 18 const VALID_POSE_MATRIX = [0, 1, 0, 0, 19 0, 0, 1, 0, 20 1, 0, 0, 0, 21 1, 1, 1, 1]; 22 23 const VALID_POSE_TRANSFORM = { 24 position: [1, 1, 1], 25 orientation: [0.5, 0.5, 0.5, 0.5] 26 }; 27 28 const VALID_PROJECTION_MATRIX = [ 29 1, 0, 0, 0, 30 0, 1, 0, 0, 31 3, 2, -1, -1, 32 0, 0, -0.2, 0 33 ]; 34 35 // This is a decomposed version of the above. 36 const VALID_FIELD_OF_VIEW = { 37 upDegrees: 71.565, 38 downDegrees: -45, 39 leftDegrees:-63.4349, 40 rightDegrees: 75.9637 41 }; 42 43 // This is roughly equivalent to the above, but with a different near plane. 44 // The fact that it's the same isn't too concerning, since to be the same 45 // ViewGeometry it'd also need the same offset. 46 const VALID_DEPTH_PROJECTION_MATRIX = [ 47 1, 0, 0, 0, 48 0, 1, 0, 0, 49 3, 2, -1, -1, 50 0, 0, -0.002, 0 51 ]; 52 53 // A valid input grip matrix for when we don't care about specific values 54 const VALID_GRIP = [1, 0, 0, 0, 55 0, 1, 0, 0, 56 0, 0, 1, 0, 57 4, 3, 2, 1]; 58 59 const VALID_GRIP_TRANSFORM = { 60 position: [4, 3, 2], 61 orientation: [0, 0, 0, 1] 62 }; 63 64 // A valid input pointer offset for when we don't care about specific values 65 const VALID_POINTER = [1, 0, 0, 0, 66 0, 1, 0, 0, 67 0, 0, 1, 0, 68 0, 0, 1, 1]; 69 70 const VALID_POINTER_TRANSFORM = { 71 position: [0, 0, 1], 72 orientation: [0, 0, 0, 1] 73 }; 74 75 // A Valid Local to floor matrix/transform for when we don't care about specific 76 // values. Note that these should be identical, just different representations. 77 const VALID_FLOOR_ORIGIN_MATRIX = [1, 0, 0, 0, 78 0, 1, 0, 0, 79 0, 0, 1, 0, 80 1, 1.65, -1, 1]; 81 82 const VALID_FLOOR_ORIGIN = { 83 position: [-1.0, -1.65, 1.0], 84 orientation: [0, 0, 0, 1] 85 }; 86 87 const VALID_BOUNDS = [ 88 { x: 3.0, z: -2.0 }, 89 { x: 3.5, z: 0.0 }, 90 { x: 3.0, z: 2.0 }, 91 { x: -3.0, z: 2.0 }, 92 { x: -3.5, z: 0.0 }, 93 { x: -3.0, z: -2.0 } 94 ]; 95 96 const VALID_RESOLUTION = { 97 width: 200, 98 height: 200 99 }; 100 101 const LEFT_OFFSET = { 102 position: [-0.1, 0, 0], 103 orientation: [0, 0, 0, 1] 104 }; 105 106 const RIGHT_OFFSET = { 107 position: [0.1, 0, 0], 108 orientation: [0, 0, 0, 1] 109 }; 110 111 // Most depth tests at present are effectively monocular, so just ensure we 112 // substantially overlap the left eye. 113 const DEPTH_OFFSET = { 114 position: [-0.1, 0.01, 0], 115 orientation: [0, 0, 0, 1] 116 }; 117 118 const FIRST_PERSON_OFFSET = { 119 position: [0, 0.1, 0], 120 orientation: [0, 0, 0, 1] 121 }; 122 123 const VALID_VIEWS = [{ 124 eye:"left", 125 projectionMatrix: VALID_PROJECTION_MATRIX, 126 viewOffset: LEFT_OFFSET, 127 resolution: VALID_RESOLUTION 128 }, { 129 eye:"right", 130 projectionMatrix: VALID_PROJECTION_MATRIX, 131 viewOffset: RIGHT_OFFSET, 132 resolution: VALID_RESOLUTION 133 }, 134 ]; 135 136 const VALID_SECONDARY_VIEWS = [{ 137 eye: "none", 138 projectionMatrix: VALID_PROJECTION_MATRIX, 139 viewOffset: FIRST_PERSON_OFFSET, 140 resolution: VALID_RESOLUTION, 141 isFirstPersonObserver: true 142 } 143 ]; 144 145 const NON_IMMERSIVE_VIEWS = [{ 146 eye: "none", 147 projectionMatrix: VALID_PROJECTION_MATRIX, 148 viewOffset: IDENTITY_TRANSFORM, 149 resolution: VALID_RESOLUTION, 150 } 151 ]; 152 153 const ALL_FEATURES = [ 154 'viewer', 155 'local', 156 'local-floor', 157 'bounded-floor', 158 'unbounded', 159 'hit-test', 160 'dom-overlay', 161 'light-estimation', 162 'anchors', 163 'depth-sensing', 164 'secondary-views', 165 'camera-access', 166 'layers' 167 ]; 168 169 const TRACKED_IMMERSIVE_DEVICE = { 170 supportsImmersive: true, 171 supportedModes: [ "inline", "immersive-vr"], 172 views: VALID_VIEWS, 173 secondaryViews: VALID_SECONDARY_VIEWS, 174 viewerOrigin: IDENTITY_TRANSFORM, 175 supportedFeatures: ALL_FEATURES, 176 environmentBlendMode: "opaque", 177 interactionMode: "world-space" 178 }; 179 180 const IMMERSIVE_AR_DEVICE = { 181 supportsImmersive: true, 182 supportedModes: [ "inline", "immersive-ar"], 183 views: VALID_VIEWS, 184 viewerOrigin: IDENTITY_TRANSFORM, 185 supportedFeatures: ALL_FEATURES, 186 environmentBlendMode: "additive", 187 interactionMode: "screen-space" 188 }; 189 190 const VALID_NON_IMMERSIVE_DEVICE = { 191 supportsImmersive: false, 192 supportedModes: ["inline"], 193 views: NON_IMMERSIVE_VIEWS, 194 viewerOrigin: IDENTITY_TRANSFORM, 195 supportedFeatures: ALL_FEATURES, 196 environmentBlendMode: "opaque", 197 interactionMode: "screen-space" 198 }; 199 200 const VALID_CONTROLLER = { 201 handedness: "none", 202 targetRayMode: "tracked-pointer", 203 pointerOrigin: VALID_POINTER_TRANSFORM, 204 profiles: [] 205 }; 206 207 const RIGHT_CONTROLLER = { 208 handedness: "right", 209 targetRayMode: "tracked-pointer", 210 pointerOrigin: VALID_POINTER_TRANSFORM, 211 profiles: [] 212 }; 213 214 const SCREEN_CONTROLLER = { 215 handedness: "none", 216 targetRayMode: "screen", 217 pointerOrigin: VALID_POINTER_TRANSFORM, 218 profiles: [] 219 }; 220 221 // From: https://immersive-web.github.io/webxr/#default-features 222 const DEFAULT_FEATURES = { 223 "inline": ["viewer"], 224 "immersive-vr": ["viewer", "local"], 225 "immersive-ar": ["viewer", "local"], 226 };