How to use _getMojoFromInputSource method in wpt

Best JavaScript code snippet using wpt

webxr-test.js

Source:webxr-test.js Github

copy

Full Screen

...690 // Find all input sources that match the profile name:691 const matching_input_sources = Array.from(this.input_sources_.values())692 .filter(input_source => input_source.profiles_.includes(subscription.profileName));693 for (const input_source of matching_input_sources) {694 const mojo_from_native_origin = this._getMojoFromInputSource(mojo_from_viewer, input_source);695 const [mojo_ray_origin, mojo_ray_direction] = this._transformRayToMojoSpace(696 subscription.ray,697 mojo_from_native_origin698 );699 const results = this._hitTestWorld(mojo_ray_origin, mojo_ray_direction, subscription.entityTypes);700 result.inputSourceIdToHitTestResults.set(input_source.source_id_, results);701 }702 frameData.hitTestSubscriptionResults.transientInputResults.push(result);703 }704 }705 // Returns 2-element array [origin, direction] of a ray in mojo space.706 // |ray| is expressed relative to native origin.707 _transformRayToMojoSpace(ray, mojo_from_native_origin) {708 const ray_origin = {709 x: ray.origin.x,710 y: ray.origin.y,711 z: ray.origin.z,712 w: 1713 };714 const ray_direction = {715 x: ray.direction.x,716 y: ray.direction.y,717 z: ray.direction.z,718 w: 0719 };720 const mojo_ray_origin = XRMathHelper.transform_by_matrix(721 mojo_from_native_origin,722 ray_origin);723 const mojo_ray_direction = XRMathHelper.transform_by_matrix(724 mojo_from_native_origin,725 ray_direction);726 return [mojo_ray_origin, mojo_ray_direction];727 }728 // Hit tests the passed in ray (expressed as origin and direction) against the mocked world data.729 _hitTestWorld(origin, direction, entityTypes) {730 let result = [];731 for (const region of this.world_.hitTestRegions) {732 const partial_result = this._hitTestRegion(733 region,734 origin, direction,735 entityTypes);736 result = result.concat(partial_result);737 }738 return result.sort((lhs, rhs) => lhs.distance - rhs.distance);739 }740 // Hit tests the passed in ray (expressed as origin and direction) against world region.741 // |entityTypes| is a set of FakeXRRegionTypes.742 // |region| is FakeXRRegion.743 // Returns array of XRHitResults, each entry will be decorated with the distance from the ray origin (along the ray).744 _hitTestRegion(region, origin, direction, entityTypes) {745 const regionNameToMojoEnum = {746 "point":device.mojom.EntityTypeForHitTest.POINT,747 "plane":device.mojom.EntityTypeForHitTest.PLANE,748 "mesh":null749 };750 if (!entityTypes.includes(regionNameToMojoEnum[region.type])) {751 return [];752 }753 const result = [];754 for (const face of region.faces) {755 const maybe_hit = this._hitTestFace(face, origin, direction);756 if (maybe_hit) {757 result.push(maybe_hit);758 }759 }760 // The results should be sorted by distance and there should be no 2 entries with761 // the same distance from ray origin - that would mean they are the same point.762 // This situation is possible when a ray intersects the region through an edge shared763 // by 2 faces.764 return result.sort((lhs, rhs) => lhs.distance - rhs.distance)765 .filter((val, index, array) => index === 0 || val.distance !== array[index - 1].distance);766 }767 // Hit tests the passed in ray (expressed as origin and direction) against a single face.768 // |face|, |origin|, and |direction| are specified in world (aka mojo) coordinates.769 // |face| is an array of DOMPointInits.770 // Returns null if the face does not intersect with the ray, otherwise the result is771 // an XRHitResult with matrix describing the pose of the intersection point.772 _hitTestFace(face, origin, direction) {773 const add = XRMathHelper.add;774 const sub = XRMathHelper.sub;775 const mul = XRMathHelper.mul;776 const normalize = XRMathHelper.normalize;777 const dot = XRMathHelper.dot;778 const cross = XRMathHelper.cross;779 const neg = XRMathHelper.neg;780 //1. Calculate plane normal in world coordinates.781 const point_A = face.vertices[0];782 const point_B = face.vertices[1];783 const point_C = face.vertices[2];784 const edge_AB = sub(point_B, point_A);785 const edge_AC = sub(point_C, point_A);786 const normal = normalize(cross(edge_AB, edge_AC));787 const numerator = dot(sub(point_A, origin), normal);788 const denominator = dot(direction, normal);789 if (Math.abs(denominator) < XRMathHelper.EPSILON) {790 // Planes are nearly parallel - there's either infinitely many intersection points or 0.791 // Both cases signify a "no hit" for us.792 return null;793 } else {794 // Single intersection point between the infinite plane and the line (*not* ray).795 // Need to calculate the hit test matrix taking into account the face vertices.796 const distance = numerator / denominator;797 if (distance < 0) {798 // Line - plane intersection exists, but not the half-line - plane does not.799 return null;800 } else {801 const intersection_point = add(origin, mul(distance, direction));802 // Since we are treating the face as a solid, flip the normal so that its803 // half-space will contain the ray origin.804 const y_axis = denominator > 0 ? neg(normal) : normal;805 let z_axis = null;806 const cos_direction_and_y_axis = dot(direction, y_axis);807 if (Math.abs(cos_direction_and_y_axis) > (1 - XRMathHelper.EPSILON)) {808 // Ray and the hit test normal are co-linear - try using the 'up' or 'right' vector's projection on the face plane as the Z axis.809 // Note: this edge case is currently not covered by the spec.810 const up = {x: 0.0, y: 1.0, z: 0.0, w: 0.0};811 const right = {x: 1.0, y: 0.0, z: 0.0, w: 0.0};812 z_axis = Math.abs(dot(up, y_axis)) > (1 - XRMathHelper.EPSILON)813 ? sub(up, mul(dot(right, y_axis), y_axis)) // `up is also co-linear with hit test normal, use `right`814 : sub(up, mul(dot(up, y_axis), y_axis)); // `up` is not co-linear with hit test normal, use it815 } else {816 // Project the ray direction onto the plane, negate it and use as a Z axis.817 z_axis = neg(sub(direction, mul(cos_direction_and_y_axis, y_axis))); // Z should point towards the ray origin, not away.818 }819 const x_axis = normalize(cross(y_axis, z_axis));820 // Filter out the points not in polygon.821 if (!XRMathHelper.pointInFace(intersection_point, face)) {822 return null;823 }824 const hitResult = new device.mojom.XRHitResult();825 hitResult.hitMatrix = new gfx.mojom.Transform();826 hitResult.distance = distance; // Extend the object with additional information used by higher layers.827 // It will not be serialized over mojom.828 hitResult.hitMatrix.matrix = new Array(16);829 hitResult.hitMatrix.matrix[0] = x_axis.x;830 hitResult.hitMatrix.matrix[1] = x_axis.y;831 hitResult.hitMatrix.matrix[2] = x_axis.z;832 hitResult.hitMatrix.matrix[3] = 0;833 hitResult.hitMatrix.matrix[4] = y_axis.x;834 hitResult.hitMatrix.matrix[5] = y_axis.y;835 hitResult.hitMatrix.matrix[6] = y_axis.z;836 hitResult.hitMatrix.matrix[7] = 0;837 hitResult.hitMatrix.matrix[8] = z_axis.x;838 hitResult.hitMatrix.matrix[9] = z_axis.y;839 hitResult.hitMatrix.matrix[10] = z_axis.z;840 hitResult.hitMatrix.matrix[11] = 0;841 hitResult.hitMatrix.matrix[12] = intersection_point.x;842 hitResult.hitMatrix.matrix[13] = intersection_point.y;843 hitResult.hitMatrix.matrix[14] = intersection_point.z;844 hitResult.hitMatrix.matrix[15] = 1;845 return hitResult;846 }847 }848 }849 _getMojoFromInputSource(mojo_from_viewer, input_source) {850 if (input_source.target_ray_mode_ === 'gaze') { // XRTargetRayMode::GAZING851 // If the pointer origin is gaze, then the result is852 // just mojo_from_viewer.853 return mojo_from_viewer;854 } else if (input_source.target_ray_mode_ === 'tracked-pointer') { // XRTargetRayMode:::POINTING855 // If the pointer origin is tracked-pointer, the result is just856 // mojo_from_input*input_from_pointer.857 return XRMathHelper.mul4x4(858 input_source.mojo_from_input_.matrix,859 input_source.input_from_pointer_.matrix);860 } else if (input_source.target_ray_mode_ === 'screen') { // XRTargetRayMode::TAPPING861 // If the pointer origin is screen, the input_from_pointer is862 // equivalent to viewer_from_pointer and the result is863 // mojo_from_viewer*viewer_from_pointer.864 return XRMathHelper.mul4x4(865 mojo_from_viewer,866 input_source.input_from_pointer_.matrix);867 } else {868 return null;869 }870 }871 _getMojoFromViewer() {872 const transform = {873 position: [874 this.pose_.position.x,875 this.pose_.position.y,876 this.pose_.position.z],877 orientation: [878 this.pose_.orientation.x,879 this.pose_.orientation.y,880 this.pose_.orientation.z,881 this.pose_.orientation.w],882 };883 return getMatrixFromTransform(transform);884 }885 _getMojoFromNativeOrigin(nativeOriginInformation) {886 const identity = function() {887 return [888 1, 0, 0, 0,889 0, 1, 0, 0,890 0, 0, 1, 0,891 0, 0, 0, 1892 ];893 };894 const mojo_from_viewer = this._getMojoFromViewer();895 if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.inputSourceId) {896 if (!this.input_sources_.has(nativeOriginInformation.inputSourceId)) {897 return null;898 } else {899 const inputSource = this.input_sources_.get(nativeOriginInformation.inputSourceId);900 return this._getMojoFromInputSource(mojo_from_viewer, inputSource);901 }902 } else if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.referenceSpaceCategory) {903 switch (nativeOriginInformation.referenceSpaceCategory) {904 case device.mojom.XRReferenceSpaceCategory.LOCAL:905 return identity();906 case device.mojom.XRReferenceSpaceCategory.LOCAL_FLOOR:907 if (this.stageParameters_ == null || this.stageParameters_.standingTransform == null) {908 console.warn("Standing transform not available.");909 return null;910 }911 // this.stageParameters_.standingTransform = floor_from_mojo aka native_origin_from_mojo912 return XRMathHelper.inverse(this.stageParameters_.standingTransform.matrix);913 case device.mojom.XRReferenceSpaceCategory.VIEWER:914 return mojo_from_viewer;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1_getMojoFromInputSource: function(inputSource) {2 var mojo = null;3 if (inputSource) {4 var inputSourceId = inputSource.id;5 if (inputSourceId) {6 var mojoId = inputSourceId.replace(/_input_source$/, '');7 mojo = this._getMojoFromId(mojoId);8 }9 }10 return mojo;11}12_getMojoFromId: function(mojoId) {13 var mojo = null;14 if (mojoId) {15 mojo = document.getElementById(mojoId);16 }17 return mojo;18}19_getInputSourceFromMojo: function(mojo) {20 var inputSource = null;21 if (mojo) {22 var mojoId = mojo.id;23 if (mojoId) {24 var inputSourceId = mojoId + "_input_source";25 inputSource = document.getElementById(inputSourceId);26 }27 }28 return inputSource;29}30_getInputSourceFromEvent: function(event) {31 var inputSource = null;32 if (event) {33 inputSource = event.target;34 }35 return inputSource;36}37_getInputSourceFromMojo: function(mojo) {38 var inputSource = null;39 if (mojo) {40 var mojoId = mojo.id;41 if (mojoId) {42 var inputSourceId = mojoId + "_input_source";43 inputSource = document.getElementById(inputSourceId);44 }45 }46 return inputSource;47}48_getInputSourceFromEvent: function(event) {49 var inputSource = null;50 if (event) {51 inputSource = event.target;52 }53 return inputSource;54}55_getMojoFromEvent: function(event) {56 var mojo = null;57 if (event) {58 var inputSource = this._getInputSourceFromEvent(event);59 mojo = this._getMojoFromInputSource(inputSource);60 }61 return mojo;62}63_getMojoFromEvent: function(event) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptouch = new WPTouch();2var inputSource = document.getElementById("inputSource");3var mojo = wptouch._getMojoFromInputSource(inputSource);4console.log(mojo);5function WPTouch() {6 this._getMojoFromInputSource = function(inputSource) {7 var mojo = inputSource.getAttribute("data-mojo");8 return mojo;9 }10}

Full Screen

Using AI Code Generation

copy

Full Screen

1var toolkit = require("wptoolkit");2console.log(source);3var toolkit = require("wptoolkit");4console.log(source);5var toolkit = require("wptoolkit");6console.log(source);7var toolkit = require("wptoolkit");8console.log(source);9var toolkit = require("wptoolkit");10console.log(source);11var toolkit = require("wptoolkit");12console.log(source);13var toolkit = require("wptoolkit");14console.log(source);15var toolkit = require("wptoolkit");16console.log(source);17var toolkit = require("wptoolkit");18console.log(source);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require("wptoolkit");2console.log(mojo);3var wptoolkit = require("wptoolkit");4console.log(mojo);5var wptoolkit = require("wptoolkit");6console.log(mojo);7var wptoolkit = require("wptoolkit");8console.log(mojo);9var wptoolkit = require("wptoolkit");10console.log(mojo);11var wptoolkit = require("wptoolkit");

Full Screen

Using AI Code Generation

copy

Full Screen

1var _wptoolkit = Components.classes["@mozilla.org/wptoolkit;1"].getService(Components.interfaces.nsIWebPlatformToolkit);2var _inputSource = _wptoolkit._getMojoFromInputSource();3dump("_inputSource: " + _inputSource + "4");5var _wptoolkit = Components.classes["@mozilla.org/wptoolkit;1"].getService(Components.interfaces.nsIWebPlatformToolkit);6var _inputSource = _wptoolkit._getInputSourceFromMojo();7dump("_inputSource: " + _inputSource + "8");9var _wptoolkit = Components.classes["@mozilla.org/wptoolkit;1"].getService(Components.interfaces.nsIWebPlatformToolkit);10var _inputSource = _wptoolkit._getInputSource();11dump("_inputSource: " + _inputSource + "12");13var _wptoolkit = Components.classes["@mozilla.org/wptoolkit;1"].getService(Components.interfaces.nsIWebPlatformToolkit);14var _inputSource = _wptoolkit._getInputSource();15dump("_inputSource: " + _inputSource + "16");17var _wptoolkit = Components.classes["@mozilla.org/wptoolkit;1"].getService(Components.interfaces.nsIWebPlatformToolkit);18_wptoolkit._setInputSource("virtualKeyboard");19dump("_inputSource: " + _inputSource + "20");

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require("wptoolkit");2var inputSource = {3};4var mojo = wptoolkit._getMojoFromInputSource(inputSource);5console.log(mojo);6var wptoolkit = require("wptoolkit");7var inputSource = {8};9var mojo = wptoolkit._getMojoFromInputSource(inputSource);10console.log(mojo);11var wptoolkit = require("wptoolkit");12var inputSource = {13};14var mojo = wptoolkit._getMojoFromInputSource(inputSource);15console.log(mojo);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('./wptools.js');2var util = require('util');3var input = {4}5var mojo = wptools._getMojoFromInputSource(input, function(err, mojo) {6 console.log(util.inspect(mojo, { showHidden: true, depth: null }));7});8{ _id: 54f9e2e2d3c3d3ca3a1d0c5a,

Full Screen

Using AI Code Generation

copy

Full Screen

1var mojoClient = _getMojoFromInputSource(inputSource);2var mojoClient = _getMojoFromInputSource(inputSource);3var mojoClient = _getMojoFromInputSource(inputSource);4var mojoClient = _getMojoFromInputSource(inputSource);5var mojoClient = _getMojoFromInputSource(inputSource);6var mojoClient = _getMojoFromInputSource(inputSource);7var mojoClient = _getMojoFromInputSource(inputSource);8var mojoClient = _getMojoFromInputSource(inputSource);9var mojoClient = _getMojoFromInputSource(inputSource);10var mojoClient = _getMojoFromInputSource(inputSource);11var mojoClient = _getMojoFromInputSource(inputSource);

Full Screen

Using AI Code Generation

copy

Full Screen

1var mojo = _getMojoFromInputSource( 'inputSource' );2var mojo = _getMojoFromInputSource( 'inputSource' );3var mojo = _getMojoFromInputSource( 'inputSource' );4var mojo = _getMojoFromInputSource( 'inputSource' );5var mojo = _getMojoFromInputSource( 'inputSource' );6var mojo = _getMojoFromInputSource( 'inputSource' );7var mojo = _getMojoFromInputSource( 'inputSource' );8var mojo = _getMojoFromInputSource( 'inputSource' );9var mojo = _getMojoFromInputSource( 'inputSource' );10var mojo = _getMojoFromInputSource( 'inputSource' );11var mojo = _getMojoFromInputSource( 'inputSource' );

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful