|
@@ -1,17 +1,19 @@
|
|
import { GLTFLoader } from '../loaders/GLTFLoader.js';
|
|
import { GLTFLoader } from '../loaders/GLTFLoader.js';
|
|
|
|
|
|
|
|
+const DEFAULT_HAND_PROFILE_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/[email protected]/dist/profiles/generic-hand/';
|
|
|
|
+
|
|
class XRHandMeshModel {
|
|
class XRHandMeshModel {
|
|
|
|
|
|
- constructor( handModel, controller, assetUrl ) {
|
|
|
|
|
|
+ constructor( handModel, controller, path, handedness ) {
|
|
|
|
|
|
this.controller = controller;
|
|
this.controller = controller;
|
|
this.handModel = handModel;
|
|
this.handModel = handModel;
|
|
|
|
|
|
this.bones = [];
|
|
this.bones = [];
|
|
- const loader = new GLTFLoader();
|
|
|
|
|
|
|
|
- loader.setPath( '' );
|
|
|
|
- loader.load( assetUrl, gltf => {
|
|
|
|
|
|
+ const loader = new GLTFLoader();
|
|
|
|
+ loader.setPath( path || DEFAULT_HAND_PROFILE_PATH );
|
|
|
|
+ loader.load( `${handedness}.glb`, gltf => {
|
|
|
|
|
|
const object = gltf.scene.children[ 0 ];
|
|
const object = gltf.scene.children[ 0 ];
|
|
this.handModel.add( object );
|
|
this.handModel.add( object );
|
|
@@ -21,6 +23,8 @@ class XRHandMeshModel {
|
|
mesh.castShadow = true;
|
|
mesh.castShadow = true;
|
|
mesh.receiveShadow = true;
|
|
mesh.receiveShadow = true;
|
|
|
|
|
|
|
|
+ mesh.material.side = 0; // Workaround: force FrontSide
|
|
|
|
+
|
|
const joints = [
|
|
const joints = [
|
|
'wrist',
|
|
'wrist',
|
|
'thumb-metacarpal',
|
|
'thumb-metacarpal',
|
|
@@ -52,6 +56,7 @@ class XRHandMeshModel {
|
|
joints.forEach( jointName => {
|
|
joints.forEach( jointName => {
|
|
|
|
|
|
const bone = object.getObjectByName( jointName );
|
|
const bone = object.getObjectByName( jointName );
|
|
|
|
+
|
|
if ( bone !== undefined ) {
|
|
if ( bone !== undefined ) {
|
|
|
|
|
|
bone.jointName = jointName;
|
|
bone.jointName = jointName;
|
|
@@ -74,15 +79,19 @@ class XRHandMeshModel {
|
|
|
|
|
|
// XR Joints
|
|
// XR Joints
|
|
const XRJoints = this.controller.joints;
|
|
const XRJoints = this.controller.joints;
|
|
|
|
+
|
|
for ( let i = 0; i < this.bones.length; i ++ ) {
|
|
for ( let i = 0; i < this.bones.length; i ++ ) {
|
|
|
|
|
|
const bone = this.bones[ i ];
|
|
const bone = this.bones[ i ];
|
|
|
|
+
|
|
if ( bone ) {
|
|
if ( bone ) {
|
|
|
|
|
|
const XRJoint = XRJoints[ bone.jointName ];
|
|
const XRJoint = XRJoints[ bone.jointName ];
|
|
|
|
+
|
|
if ( XRJoint.visible ) {
|
|
if ( XRJoint.visible ) {
|
|
|
|
|
|
const position = XRJoint.position;
|
|
const position = XRJoint.position;
|
|
|
|
+
|
|
if ( bone ) {
|
|
if ( bone ) {
|
|
|
|
|
|
bone.position.copy( position );
|
|
bone.position.copy( position );
|