Преглед на файлове

Even more bug fixes

Turns out that after the caching changes the controllers were loading fast enough that `this.remove( this.children[ 0 ] );` in the example code was removing the controller mesh and not the targeting visualization as intended.
Brandon Jones преди 5 години
родител
ревизия
5812a5acc0
променени са 3 файла, в които са добавени 13 реда и са изтрити 8 реда
  1. 4 2
      examples/jsm/webxr/XRControllerModelFactory.js
  2. 6 4
      examples/webxr_vr_ballshooter.html
  3. 3 2
      examples/webxr_vr_cubes.html

+ 4 - 2
examples/jsm/webxr/XRControllerModelFactory.js

@@ -20,6 +20,7 @@ import {
 } from '../libs/motion-controllers.module.js';
 
 const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/[email protected]/dist/profiles';
+const DEFAULT_PROFILE = 'generic-trigger';
 
 function XRControllerModel( ) {
 
@@ -236,9 +237,9 @@ var XRControllerModelFactory = ( function () {
 
 				const xrInputSource = event.data;
 
-				if (xrInputSource.targetRayMode !== 'tracked-pointer' ) return;
+				if (xrInputSource.targetRayMode !== 'tracked-pointer' || !xrInputSource.gamepad ) return;
 
-				fetchProfile(xrInputSource, this.path).then(({ profile, assetPath }) => {
+				fetchProfile( xrInputSource, this.path, DEFAULT_PROFILE ).then(({ profile, assetPath }) => {
 
 					controllerModel.motionController = new MotionController(
 						xrInputSource,
@@ -292,6 +293,7 @@ var XRControllerModelFactory = ( function () {
 
 				controllerModel.motionController = null;
 				controllerModel.remove( scene );
+				scene = null;
 
 			});
 

+ 6 - 4
examples/webxr_vr_ballshooter.html

@@ -108,12 +108,13 @@
 				controller1.addEventListener( 'selectend', onSelectEnd );
 				controller1.addEventListener( 'connected', function ( event ) {
 
-					this.add( buildController( event.data ) );
+					this.userData.targetMesh = buildController( event.data );
+					this.add( this.userData.targetMesh );
 
 				} );
 				controller1.addEventListener( 'disconnected', function () {
 
-					this.remove( this.children[ 0 ] );
+					this.remove( this.userData.targetMesh );
 
 				} );
 				scene.add( controller1 );
@@ -123,12 +124,13 @@
 				controller2.addEventListener( 'selectend', onSelectEnd );
 				controller2.addEventListener( 'connected', function ( event ) {
 
-					this.add( buildController( event.data ) );
+					this.userData.targetMesh = buildController( event.data );
+					this.add( this.userData.targetMesh );
 
 				} );
 				controller2.addEventListener( 'disconnected', function () {
 
-					this.remove( this.children[ 0 ] );
+					this.remove( this.userData.targetMesh );
 
 				} );
 				scene.add( controller2 );

+ 3 - 2
examples/webxr_vr_cubes.html

@@ -113,12 +113,13 @@
 				controller.addEventListener( 'selectend', onSelectEnd );
 				controller.addEventListener( 'connected', function ( event ) {
 
-					this.add( buildController( event.data ) );
+					this.userData.targetMesh = buildController( event.data );
+					this.add( this.userData.targetMesh );
 
 				} );
 				controller.addEventListener( 'disconnected', function () {
 
-					this.remove( this.children[ 0 ] );
+					this.remove( this.userData.targetMesh );
 
 				} );
 				scene.add( controller );