Prechádzať zdrojové kódy

SphereHands => PrimitiveHands

Fernando Serrano 5 rokov pred
rodič
commit
829bdfe35f

+ 11 - 7
examples/jsm/webxr/WebXRHandController.js

@@ -3,8 +3,8 @@ import {
 } from "../../../build/three.module.js";
 
 import {
-	XRHandSpheresModel
-} from "./XRHandSpheresModel.js";
+	XRHandPrimitiveModel
+} from "./XRHandPrimitiveModel.js";
 
 import {
 	XRHandOculusMeshModel
@@ -48,7 +48,7 @@ var XRHandModelFactory = ( function () {
 
 		constructor: XRHandModelFactory,
 
-		createHandModel: function ( controller, profile ) {
+		createHandModel: function ( controller, profile, options ) {
 
 			const handModel = new XRHandModel( controller );
 			let scene = null;
@@ -63,13 +63,17 @@ var XRHandModelFactory = ( function () {
 					handModel.xrInputSource = xrInputSource;
 
 					// @todo Detect profile if not provided
-					if ( profile === "spheres" ) {
+					if ( profile === undefined || profile === "spheres" ) {
 
-						handModel.motionController = new XRHandSpheresModel( controller, xrInputSource.handedness );
+						handModel.motionController = new XRHandPrimitiveModel( controller, xrInputSource.handedness, { primitive: "sphere" } );
 
-					} else {
+					} else if ( profile === "boxes" ) {
 
-						handModel.motionController = new XRHandOculusMeshModel( controller, xrInputSource.handedness );
+						handModel.motionController = new XRHandPrimitiveModel( controller, xrInputSource.handedness, { primitive: "box" } );
+
+					} else if ( profile === "oculus" ) {
+
+						handModel.motionController = new XRHandOculusMeshModel( controller, xrInputSource.handedness, options );
 
 					}
 

+ 16 - 5
examples/jsm/webxr/XRHandSpheresModel.js → examples/jsm/webxr/XRHandPrimitiveModel.js

@@ -1,24 +1,35 @@
 import {
 	SphereBufferGeometry,
+	BoxBufferGeometry,
 	MeshStandardMaterial,
 	Mesh,
 	Group
 } from "../../../build/three.module.js";
 
-class XRHandSpheresModel {
+class XRHandPrimitiveModel {
 
-	constructor( controller/*, handedness */ ) {
+	constructor( controller, handedness, options ) {
 
 		this.controller = controller;
 
 	  this.envMap = null;
 
 		this.handMesh = new Group();
-		this.controller.add(this.handMesh);
+		this.controller.add( this.handMesh );
 
 		if ( window.XRHand ) {
 
-			var geometry = new SphereBufferGeometry( 1, 10, 10 );
+			var geometry;
+			if ( ! options || ! options.primitive || options.primitive === "sphere" ) {
+
+				geometry = new SphereBufferGeometry( 1, 10, 10 );
+
+			} else if ( options.primitive === "box" ) {
+
+				geometry = new BoxBufferGeometry( 1, 1, 1 );
+
+			}
+
 			var jointMaterial = new MeshStandardMaterial( { color: 0x000000, roughness: 0.2, metalness: 0.8 } );
 			var tipMaterial = new MeshStandardMaterial( { color: 0x333333, roughness: 0.2, metalness: 0.8 } );
 
@@ -69,4 +80,4 @@ class XRHandSpheresModel {
 
 }
 
-export { XRHandSpheresModel };
+export { XRHandPrimitiveModel };