WebXR - Hit test feature is not supported

Hi there,

I’m trying to add support for AR to a project. I’ve tried this hit test example on my devices, and it was working fine.

I then pretty much copied the code from the above example but I’m getting the following error

Uncaught (in promise) DOMException: Failed to execute ‘requestHitTestSource’ on ‘XRSession’: Hit test feature is not supported.

below is the function in typescript.

private render(timestamp:any, frame:any){
	if (this.allAssets && frame) {
		var referenceSpace:any = this.renderer.xr.getReferenceSpace();
		var session:any = this.renderer.xr.getSession();
		
		if ( this.hitTestSourceRequested === false ) {
			session.requestReferenceSpace( 'viewer' ).then( ( referenceSpace: any ) => {
				session.requestHitTestSource( { space: referenceSpace } ).then( ( source: any ) => {
					this.hitTestSource = source;
				});

				session.addEventListener( 'end', () => {
					this.hitTestSourceRequested = false;
					this.hitTestSource = null;
				});

				this.hitTestSourceRequested = true;
			});
		}

		if ( this.hitTestSource ) {
			var hitTestResults = frame.getHitTestResults( this.hitTestSource );
			if ( hitTestResults.length ) {
				var hit = hitTestResults[ 0 ];
				this.reticle.visible = true;
				this.reticle.matrix.fromArray( hit.getPose( referenceSpace ).transform.matrix );
			}
			else {
				this.reticle.visible = false;
			}
		}
	}

	this.renderer.render( this.scene, this.camera );
}

Any ideas?

1 Like

I may have found something, I was creating the ARButton with this code

document.body.appendChild( ARButton.createButton( this.renderer ) );

instead of

document.body.appendChild( ARButton.createButton( this.renderer, { requiredFeatures: [ 'hit-test' ] } ) );

but this function says it doesn’t support 2 arguements. :frowning:

1 Like

hm… apparently it was an issue with the ThreeJS version I was using. I had 113.2. I’ve tried to upgrade to the latest, but this was breaking in multiple other places. So, as a quick hack, I’ve just copied the files from the webxr folder, from 120 in the 113.2. Not the most elegant, but it works for now.