For the hand example this should work to determine if to add hand models with visionOS and others.
controller1 = renderer.xr.getController( 0 );
scene.add( controller1 );
controller2 = renderer.xr.getController( 1 );
scene.add( controller2 );
controller1.addEventListener( 'connected', function ( event ) {
//console.log("connected ", event.data.handedness );
const geometry = new THREE.BufferGeometry().setFromPoints( [ new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 0, - 1 ) ] );
const line = new THREE.Line( geometry );
line.name = 'line';
line.scale.z = 5;
controller1.add( line.clone() );
controller2.add( line.clone() );
} );
renderer.xr.addEventListener("sessionstart", (e) => {
const session = renderer.xr.getSession(),
isIOS = ((/iPad/i).test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1));
//console.log("Session started", session);
//visionOS with inputSources
const visionOSWithControls = isIOS && session.inputSources && session.inputSources.length,
hasHandTracking = session.enabledFeatures && session.enabledFeatures.indexOf("hand-tracking") > 0;
if (hasHandTracking || visionOSWithControls) {
console.log("supports hand tracking");
const controllerModelFactory = new XRControllerModelFactory();
const handModelFactory = new XRHandModelFactory();
// Hand 1
controllerGrip1 = renderer.xr.getControllerGrip( 0 );
controllerGrip1.add( controllerModelFactory.createControllerModel( controllerGrip1 ) );
scene.add( controllerGrip1 );
hand1 = renderer.xr.getHand( 0 );
hand1.add( handModelFactory.createHandModel( hand1 ) );
scene.add( hand1 );
// Hand 2
controllerGrip2 = renderer.xr.getControllerGrip( 1 );
controllerGrip2.add( controllerModelFactory.createControllerModel( controllerGrip2 ) );
scene.add( controllerGrip2 );
hand2 = renderer.xr.getHand( 1 );
hand2.add( handModelFactory.createHandModel( hand2 ) );
scene.add( hand2 );
} else {
console.log("No hand tracking support");
}
//console.log("session start ", renderer.xr.getSession());
});