|
@@ -44,7 +44,7 @@ XRControllerModel.prototype = Object.assign( Object.create( Object3D.prototype )
|
|
|
}
|
|
|
|
|
|
this.envMap = envMap;
|
|
|
- this.traverse(( child ) => {
|
|
|
+ this.traverse( ( child ) => {
|
|
|
|
|
|
if ( child.isMesh ) {
|
|
|
|
|
@@ -53,7 +53,7 @@ XRControllerModel.prototype = Object.assign( Object.create( Object3D.prototype )
|
|
|
|
|
|
}
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
return this;
|
|
|
|
|
@@ -67,22 +67,22 @@ XRControllerModel.prototype = Object.assign( Object.create( Object3D.prototype )
|
|
|
|
|
|
Object3D.prototype.updateMatrixWorld.call( this, force );
|
|
|
|
|
|
- if ( !this.motionController ) return;
|
|
|
+ if ( ! this.motionController ) return;
|
|
|
|
|
|
// Cause the MotionController to poll the Gamepad for data
|
|
|
this.motionController.updateFromGamepad();
|
|
|
|
|
|
// Update the 3D model to reflect the button, thumbstick, and touchpad state
|
|
|
- Object.values( this.motionController.components ).forEach(( component ) => {
|
|
|
+ Object.values( this.motionController.components ).forEach( ( component ) => {
|
|
|
|
|
|
// Update node data based on the visual responses' current states
|
|
|
- Object.values( component.visualResponses ).forEach(( visualResponse ) => {
|
|
|
+ Object.values( component.visualResponses ).forEach( ( visualResponse ) => {
|
|
|
|
|
|
const { valueNode, minNode, maxNode, value, valueNodeProperty } = visualResponse;
|
|
|
|
|
|
// Skip if the visual response node is not found. No error is needed,
|
|
|
// because it will have been reported at load time.
|
|
|
- if ( !valueNode ) return;
|
|
|
+ if ( ! valueNode ) return;
|
|
|
|
|
|
// Calculate the new properties based on the weight supplied
|
|
|
if ( valueNodeProperty === MotionControllerConstants.VisualResponseProperty.VISIBILITY ) {
|
|
@@ -106,9 +106,9 @@ XRControllerModel.prototype = Object.assign( Object.create( Object3D.prototype )
|
|
|
|
|
|
}
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -122,75 +122,80 @@ XRControllerModel.prototype = Object.assign( Object.create( Object3D.prototype )
|
|
|
function findNodes( motionController, scene ) {
|
|
|
|
|
|
// Loop through the components and find the nodes needed for each components' visual responses
|
|
|
- Object.values( motionController.components ).forEach(( component ) => {
|
|
|
+ Object.values( motionController.components ).forEach( ( component ) => {
|
|
|
|
|
|
const { type, touchPointNodeName, visualResponses } = component;
|
|
|
|
|
|
- if (type === MotionControllerConstants.ComponentType.TOUCHPAD) {
|
|
|
+ if ( type === MotionControllerConstants.ComponentType.TOUCHPAD ) {
|
|
|
|
|
|
component.touchPointNode = scene.getObjectByName( touchPointNodeName );
|
|
|
if ( component.touchPointNode ) {
|
|
|
|
|
|
// Attach a touch dot to the touchpad.
|
|
|
const sphereGeometry = new SphereGeometry( 0.001 );
|
|
|
- const material = new MeshBasicMaterial({ color: 0x0000FF });
|
|
|
+ const material = new MeshBasicMaterial( { color: 0x0000FF } );
|
|
|
const sphere = new Mesh( sphereGeometry, material );
|
|
|
component.touchPointNode.add( sphere );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- console.warn(`Could not find touch dot, ${component.touchPointNodeName}, in touchpad component ${componentId}`);
|
|
|
+ console.warn( `Could not find touch dot, ${component.touchPointNodeName}, in touchpad component ${componentId}` );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// Loop through all the visual responses to be applied to this component
|
|
|
- Object.values( visualResponses ).forEach(( visualResponse ) => {
|
|
|
+ Object.values( visualResponses ).forEach( ( visualResponse ) => {
|
|
|
|
|
|
const { valueNodeName, minNodeName, maxNodeName, valueNodeProperty } = visualResponse;
|
|
|
|
|
|
// If animating a transform, find the two nodes to be interpolated between.
|
|
|
if ( valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM ) {
|
|
|
|
|
|
- visualResponse.minNode = scene.getObjectByName(minNodeName);
|
|
|
- visualResponse.maxNode = scene.getObjectByName(maxNodeName);
|
|
|
+ visualResponse.minNode = scene.getObjectByName( minNodeName );
|
|
|
+ visualResponse.maxNode = scene.getObjectByName( maxNodeName );
|
|
|
|
|
|
// If the extents cannot be found, skip this animation
|
|
|
- if ( !visualResponse.minNode ) {
|
|
|
+ if ( ! visualResponse.minNode ) {
|
|
|
|
|
|
- console.warn(`Could not find ${minNodeName} in the model`);
|
|
|
+ console.warn( `Could not find ${minNodeName} in the model` );
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( !visualResponse.maxNode ) {
|
|
|
+ if ( ! visualResponse.maxNode ) {
|
|
|
|
|
|
- console.warn(`Could not find ${maxNodeName} in the model`);
|
|
|
+ console.warn( `Could not find ${maxNodeName} in the model` );
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// If the target node cannot be found, skip this animation
|
|
|
- visualResponse.valueNode = scene.getObjectByName(valueNodeName);
|
|
|
- if ( !visualResponse.valueNode ) {
|
|
|
+ visualResponse.valueNode = scene.getObjectByName( valueNodeName );
|
|
|
+ if ( ! visualResponse.valueNode ) {
|
|
|
|
|
|
- console.warn(`Could not find ${valueNodeName} in the model`);
|
|
|
+ console.warn( `Could not find ${valueNodeName} in the model` );
|
|
|
|
|
|
}
|
|
|
- });
|
|
|
- });
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function addAssetSceneToControllerModel( controllerModel, scene ) {
|
|
|
+
|
|
|
// Find the nodes needed for animation and cache them on the motionController.
|
|
|
findNodes( controllerModel.motionController, scene );
|
|
|
|
|
|
// Apply any environment map that the mesh already has set.
|
|
|
if ( controllerModel.envMap ) {
|
|
|
|
|
|
- scene.traverse(( child ) => {
|
|
|
+ scene.traverse( ( child ) => {
|
|
|
|
|
|
if ( child.isMesh ) {
|
|
|
|
|
@@ -199,12 +204,13 @@ function addAssetSceneToControllerModel( controllerModel, scene ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
}
|
|
|
|
|
|
// Add the glTF scene to the controllerModel.
|
|
|
controllerModel.add( scene );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
var XRControllerModelFactory = ( function () {
|
|
@@ -216,7 +222,7 @@ var XRControllerModelFactory = ( function () {
|
|
|
this._assetCache = {};
|
|
|
|
|
|
// If a GLTFLoader wasn't supplied to the constructor create a new one.
|
|
|
- if ( !this.gltfLoader ) {
|
|
|
+ if ( ! this.gltfLoader ) {
|
|
|
|
|
|
this.gltfLoader = new GLTFLoader();
|
|
|
|
|
@@ -237,9 +243,9 @@ var XRControllerModelFactory = ( function () {
|
|
|
|
|
|
const xrInputSource = event.data;
|
|
|
|
|
|
- if (xrInputSource.targetRayMode !== 'tracked-pointer' || !xrInputSource.gamepad ) return;
|
|
|
+ if ( xrInputSource.targetRayMode !== 'tracked-pointer' || ! xrInputSource.gamepad ) return;
|
|
|
|
|
|
- fetchProfile( xrInputSource, this.path, DEFAULT_PROFILE ).then(({ profile, assetPath }) => {
|
|
|
+ fetchProfile( xrInputSource, this.path, DEFAULT_PROFILE ).then( ( { profile, assetPath } ) => {
|
|
|
|
|
|
controllerModel.motionController = new MotionController(
|
|
|
xrInputSource,
|
|
@@ -247,47 +253,47 @@ var XRControllerModelFactory = ( function () {
|
|
|
assetPath
|
|
|
);
|
|
|
|
|
|
- let cachedAsset = this._assetCache[controllerModel.motionController.assetUrl];
|
|
|
- if (cachedAsset) {
|
|
|
+ let cachedAsset = this._assetCache[ controllerModel.motionController.assetUrl ];
|
|
|
+ if ( cachedAsset ) {
|
|
|
|
|
|
scene = cachedAsset.scene.clone();
|
|
|
|
|
|
- addAssetSceneToControllerModel(controllerModel, scene);
|
|
|
+ addAssetSceneToControllerModel( controllerModel, scene );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- if ( !this.gltfLoader ) {
|
|
|
+ if ( ! this.gltfLoader ) {
|
|
|
|
|
|
- throw new Error(`GLTFLoader not set.`);
|
|
|
+ throw new Error( `GLTFLoader not set.` );
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.gltfLoader.setPath('');
|
|
|
+ this.gltfLoader.setPath( '' );
|
|
|
this.gltfLoader.load( controllerModel.motionController.assetUrl, ( asset ) => {
|
|
|
|
|
|
- this._assetCache[controllerModel.motionController.assetUrl] = asset;
|
|
|
+ this._assetCache[ controllerModel.motionController.assetUrl ] = asset;
|
|
|
|
|
|
scene = asset.scene.clone();
|
|
|
|
|
|
- addAssetSceneToControllerModel(controllerModel, scene);
|
|
|
+ addAssetSceneToControllerModel( controllerModel, scene );
|
|
|
|
|
|
},
|
|
|
null,
|
|
|
() => {
|
|
|
|
|
|
- throw new Error(`Asset ${motionController.assetUrl} missing or malformed.`);
|
|
|
+ throw new Error( `Asset ${motionController.assetUrl} missing or malformed.` );
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
}
|
|
|
|
|
|
- }).catch((err) => {
|
|
|
+ } ).catch( ( err ) => {
|
|
|
|
|
|
- console.warn(err);
|
|
|
+ console.warn( err );
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
controller.addEventListener( 'disconnected', () => {
|
|
|
|
|
@@ -295,7 +301,7 @@ var XRControllerModelFactory = ( function () {
|
|
|
controllerModel.remove( scene );
|
|
|
scene = null;
|
|
|
|
|
|
- });
|
|
|
+ } );
|
|
|
|
|
|
return controllerModel;
|
|
|
|