Best JavaScript code snippet using wpt
webxr-test.js
Source:webxr-test.js
...514 bufferSize: {},515 stageParameters: this.stageParameters_,516 stageParametersUpdated: stage_parameters_updated,517 };518 this._calculateHitTestResults(frameData);519 this._injectAdditionalFrameData(options, frameData);520 return Promise.resolve({521 frameData: frameData,522 });523 }524 getEnvironmentIntegrationProvider(environmentProviderRequest) {525 this.environmentProviderBinding_ = new mojo.AssociatedBinding(526 device.mojom.XREnvironmentIntegrationProvider, this,527 environmentProviderRequest);528 }529 // Note that if getEnvironmentProvider hasn't finished running yet this will530 // be undefined. It's recommended that you allow a successful task to post531 // first before attempting to close.532 closeEnvironmentIntegrationProvider() {533 this.environmentProviderBinding_.close();534 }535 closeDataProvider() {536 this.dataProviderBinding_.close();537 }538 updateSessionGeometry(frame_size, display_rotation) {539 // This function must exist to ensure that calls to it do not crash, but we540 // do not have any use for this data at present.541 }542 // XREnvironmentIntegrationProvider implementation:543 subscribeToHitTest(nativeOriginInformation, entityTypes, ray) {544 if (!this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) {545 // Reject outside of AR.546 return Promise.resolve({547 result : device.mojom.SubscribeToHitTestResult.FAILURE_GENERIC,548 subscriptionId : 0549 });550 }551 if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.inputSourceId) {552 if (!this.input_sources_.has(nativeOriginInformation.inputSourceId)) {553 // Reject - unknown input source ID.554 return Promise.resolve({555 result : device.mojom.SubscribeToHitTestResult.FAILURE_GENERIC,556 subscriptionId : 0557 });558 }559 } else if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.referenceSpaceCategory) {560 // Bounded_floor & unbounded ref spaces are not yet supported for AR:561 if (nativeOriginInformation.referenceSpaceCategory == device.mojom.XRReferenceSpaceCategory.UNBOUNDED562 || nativeOriginInformation.referenceSpaceCategory == device.mojom.XRReferenceSpaceCategory.BOUNDED_FLOOR) {563 return Promise.resolve({564 result : device.mojom.SubscribeToHitTestResult.FAILURE_GENERIC,565 subscriptionId : 0566 });567 }568 } else {569 // Planes and anchors are not yet supported by the mock interface.570 return Promise.resolve({571 result : device.mojom.SubscribeToHitTestResult.FAILURE_GENERIC,572 subscriptionId : 0573 });574 }575 // Store the subscription information as-is:576 const id = this.next_hit_test_id_++;577 this.hitTestSubscriptions_.set(id, { nativeOriginInformation, entityTypes, ray });578 return Promise.resolve({579 result : device.mojom.SubscribeToHitTestResult.SUCCESS,580 subscriptionId : id581 });582 }583 // Utility function584 requestRuntimeSession(sessionOptions) {585 return this.runtimeSupportsSession(sessionOptions).then((result) => {586 // The JavaScript bindings convert c_style_names to camelCase names.587 const options = new device.mojom.XRPresentationTransportOptions();588 options.transportMethod =589 device.mojom.XRPresentationTransportMethod.SUBMIT_AS_MAILBOX_HOLDER;590 options.waitForTransferNotification = true;591 options.waitForRenderNotification = true;592 let submit_frame_sink;593 if (result.supportsSession) {594 submit_frame_sink = {595 clientReceiver: this.presentation_provider_.getClientReceiver(),596 provider: this.presentation_provider_.bindProvider(sessionOptions),597 transportOptions: options598 };599 const dataProviderPtr = new device.mojom.XRFrameDataProviderPtr();600 const dataProviderRequest = mojo.makeRequest(dataProviderPtr);601 this.dataProviderBinding_ = new mojo.Binding(602 device.mojom.XRFrameDataProvider, this, dataProviderRequest);603 const clientReceiver = mojo.makeRequest(this.sessionClient_);604 const enabled_features = [];605 for (let i = 0; i < sessionOptions.requiredFeatures.length; i++) {606 if (this.supportedFeatures_.indexOf(sessionOptions.requiredFeatures[i]) !== -1) {607 enabled_features.push(sessionOptions.requiredFeatures[i]);608 } else {609 return Promise.resolve({session: null});610 }611 }612 for (let i =0; i < sessionOptions.optionalFeatures.length; i++) {613 if (this.supportedFeatures_.indexOf(sessionOptions.optionalFeatures[i]) !== -1) {614 enabled_features.push(sessionOptions.optionalFeatures[i]);615 }616 }617 return Promise.resolve({618 session: {619 submitFrameSink: submit_frame_sink,620 dataProvider: dataProviderPtr,621 clientReceiver: clientReceiver,622 displayInfo: this.displayInfo_,623 enabledFeatures: enabled_features,624 }625 });626 } else {627 return Promise.resolve({session: null});628 }629 });630 }631 runtimeSupportsSession(options) {632 return Promise.resolve({633 supportsSession: this.supportedModes_.includes(options.mode)634 });635 }636 // Private functions - hit test implementation:637 // Modifies passed in frameData to add hit test results.638 _calculateHitTestResults(frameData) {639 if (!this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) {640 return;641 }642 frameData.hitTestSubscriptionResults = new device.mojom.XRHitTestSubscriptionResultsData();643 frameData.hitTestSubscriptionResults.results = [];644 frameData.hitTestSubscriptionResults.transientInputResults = [];645 if (!this.world_) {646 return;647 }648 // Non-transient hit test:649 for (const [id, subscription] of this.hitTestSubscriptions_) {650 const mojo_from_native_origin = this._getMojoFromNativeOrigin(subscription.nativeOriginInformation);651 if (!mojo_from_native_origin) continue;652 const ray_origin = {x: subscription.ray.origin.x, y: subscription.ray.origin.y, z: subscription.ray.origin.z, w: 1};...
Using AI Code Generation
1var text = new BABYLON.GUI.TextBlock();2text.text = "Hello World!";3text.color = "white";4text.fontSize = 24;5text.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;6text.textVerticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;7text.paddingLeft = "20px";8text.paddingRight = "20px";9text.paddingTop = "20px";10text.paddingBottom = "20px";11text.width = 0.5;12text.height = 0.5;13text.top = 0.25;14text.left = 0.25;15text.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP;16text.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;17text.isHitTestVisible = true;18text.onPointerMoveObservable.add(function (eventData, eventState) {19 if (text._calculateHitTestResults(eventData.x, eventData.y)) {20 console.log("pointer over text");21 }22 else {23 console.log("pointer outside text");24 }25});26gui.addControl(text);27var TextBlock = (function (_super) {28 __extends(TextBlock, _super);29 function TextBlock(name) {30 var _this = _super.call(this, name) || this;31 _this.name = name || "TextBlock";32 _this._text = "";33 _this._textWrapping = false;34 _this._textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;35 _this._textVerticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;36 _this._lineSpacing = "120%";37 _this._resizeToFit = false;38 _this._resizeToFitVerticalOnly = false;39 _this._resizeToFitPadding = 0;40 _this._textWrapping = false;41 _this._textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;42 _this._textVerticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;43 _this._lineSpacing = "120%";44 _this._resizeToFit = false;45 _this._resizeToFitVerticalOnly = false;
Using AI Code Generation
1var wptexture = BABYLON.Mesh.CreatePlane("wptexture", 100, scene);2wptexture.material = new BABYLON.StandardMaterial("wptexture", scene);3var pickResult = wptexture._calculateHitTestResults(scene, 0, 0);4if (pickResult.hit){5 console.log("hit");6 console.log("faceId: " + pickResult.faceId);7 console.log("distance: " + pickResult.distance);8 console.log("pickedPoint: " + pickResult.pickedPoint);9 console.log("pickedMesh: " + pickResult.pickedMesh);10 console.log("pickedSprite: " + pickResult.pickedSprite);11 console.log("getNormal: " + pickResult.getNormal());12 console.log("getTextureCoordinates: " + pickResult.getTextureCoordinates());13}14BABYLON.Mesh.prototype._calculateHitTestResults = function(scene, x, y) {15 var result = this.intersects(scene.activeCamera, false);16 if (result.hit) {17 var hit = new BABYLON.PickingInfo();18 hit.hit = true;19 hit.distance = result.distance;20 hit.pickedPoint = result.pickedPoint;21 hit.pickedMesh = result.pickedMesh;22 hit.pickedSprite = result.pickedSprite;23 hit.getNormal = function() {24 return result.getNormal();25 };26 hit.getTextureCoordinates = function() {27 return result.getTextureCoordinates();28 };29 return hit;30 }31 return result;32};
Using AI Code Generation
1var textInput = new WPTextInput();2textInput.text = 'hello world';3textInput.font = '20px sans-serif';4textInput.x = 0;5textInput.y = 0;6var canvas = document.getElementById('canvas');7var ctx = canvas.getContext('2d');8ctx.fillStyle = 'black';9ctx.fillRect(0,0,canvas.width,canvas.height);10ctx.fillStyle = 'white';11ctx.font = '20px sans-serif';12ctx.fillText('hello world', 0, 20);13var hitTestResults = textInput._calculateHitTestResults(0, 0);14console.log(hitTestResults);15var hitTestResults = textInput._calculateHitTestResults(0, 40);16console.log(hitTestResults);17var hitTestResults = textInput._calculateHitTestResults(100, 0);18console.log(hitTestResults);19var hitTestResults = textInput._calculateHitTestResults(100, 40);20console.log(hitTestResults);21var hitTestResults = textInput._calculateHitTestResults(20, 0);22console.log(hitTestResults);23var hitTestResults = textInput._calculateHitTestResults(20, 40);24console.log(hitTestResults);25var hitTestResults = textInput._calculateHitTestResults(10, 0);26console.log(hitTestResults);27var hitTestResults = textInput._calculateHitTestResults(10, 40);28console.log(hitTestResults);
Using AI Code Generation
1var wwd = new WorldWind.WorldWindow("canvasOne");2wwd.addLayer(new WorldWind.LayerManager(wwd));3wwd.addLayer(new WorldWind.CompassLayer());4wwd.addLayer(new WorldWind.CoordinatesDisplayLayer(wwd));5wwd.addLayer(new WorldWind.ViewControlsLayer(wwd));6wwd.addLayer(new WorldWind.BMNGLayer());7wwd.addLayer(new WorldWind.BMNGLandsatLayer());8wwd.addLayer(new WorldWind.BingAerialWithLabelsLayer(null));9wwd.addLayer(new WorldWind.BingRoadsLayer(null));10wwd.addLayer(new WorldWind.BingAerialLayer(null));11wwd.addLayer(new WorldWind.BingImageryMetadataLayer(null));12wwd.addLayer(new WorldWind.BingAerialWithLabelsLayer(null));13wwd.addLayer(new WorldWind.BingRoadsLayer(null));14wwd.addLayer(new WorldWind.BingAerialLayer(null));15wwd.addLayer(new WorldWind.BingImageryMetadataLayer(null));16wwd.addLayer(new WorldWind.BingAerialWith
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!