Browse Source

Add SetPath to XRHandModelFactory

Fernando Serrano 5 years ago
parent
commit
d04f3f0677

+ 14 - 4
examples/jsm/webxr/XRHandModelFactory.js

@@ -42,12 +42,22 @@ XRHandModel.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 var XRHandModelFactory = ( function () {
 
-	function XRHandModelFactory() {}
+	function XRHandModelFactory() {
+
+		this.path = '';
+
+	}
 
 	XRHandModelFactory.prototype = {
 
 		constructor: XRHandModelFactory,
 
+		setPath: function ( path ) {
+
+			this.path = path;
+
+		},
+
 		createHandModel: function ( controller, profile, options ) {
 
 			const handModel = new XRHandModel( controller );
@@ -65,15 +75,15 @@ var XRHandModelFactory = ( function () {
 					// @todo Detect profile if not provided
 					if ( profile === undefined || profile === "spheres" ) {
 
-						handModel.motionController = new XRHandPrimitiveModel( handModel, controller, xrInputSource.handedness, { primitive: "sphere" } );
+						handModel.motionController = new XRHandPrimitiveModel( handModel, controller, this.path, xrInputSource.handedness, { primitive: "sphere" } );
 
 					} else if ( profile === "boxes" ) {
 
-						handModel.motionController = new XRHandPrimitiveModel( handModel, controller, xrInputSource.handedness, { primitive: "box" } );
+						handModel.motionController = new XRHandPrimitiveModel( handModel, controller, this.path, xrInputSource.handedness, { primitive: "box" } );
 
 					} else if ( profile === "oculus" ) {
 
-						handModel.motionController = new XRHandOculusMeshModel( handModel, controller, xrInputSource.handedness, options );
+						handModel.motionController = new XRHandOculusMeshModel( handModel, controller, this.path, xrInputSource.handedness, options );
 
 					}
 

+ 3 - 2
examples/jsm/webxr/XRHandOculusMeshModel.js

@@ -2,7 +2,7 @@ import { FBXLoader } from "../loaders/FBXLoader.js";
 
 class XRHandOculusMeshModel {
 
-	constructor( handModel, controller, handedness, options ) {
+	constructor( handModel, controller, path, handedness, options ) {
 
 		this.controller = controller;
 		this.handModel = handModel;
@@ -11,7 +11,8 @@ class XRHandOculusMeshModel {
 		var loader = new FBXLoader();
 		const low = options && options.model === "lowpoly" ? "_low" : "";
 
-		loader.load( `../../models/fbx/OculusHand_${handedness === "right" ? "R" : "L"}${low}.fbx`, object => {
+		loader.setPath( path );
+		loader.load( `fbx/OculusHand_${handedness === "right" ? "R" : "L"}${low}.fbx`, object => {
 
 			this.handModel.add( object );
 			// Hack because of the scale of the skinnedmesh

+ 1 - 1
examples/jsm/webxr/XRHandPrimitiveModel.js

@@ -8,7 +8,7 @@ import {
 
 class XRHandPrimitiveModel {
 
-	constructor( handModel, controller, handedness, options ) {
+	constructor( handModel, controller, path, handedness, options ) {
 
 		this.controller = controller;
 		this.handModel = handModel;

+ 2 - 1
examples/webxr_vr_handinput_profiles.html

@@ -92,7 +92,7 @@
 
 				container.appendChild( renderer.domElement );
 
-				document.body.appendChild( VRButton.createButton( renderer ) );
+				document.body.appendChild( VRButton.createButton( renderer, { handTracking: true } ) );
 
 				// controllers
 
@@ -104,6 +104,7 @@
 
 				var controllerModelFactory = new XRControllerModelFactory();
 				var handModelFactory = new XRHandModelFactory();
+				handModelFactory.setPath( "./models/" );
 
 				// Hand 1