Skip to content

Commit

Permalink
motion-controller: Allow sperate material overrides for hand and cont…
Browse files Browse the repository at this point in the history
…roller models
  • Loading branch information
mrxz committed Feb 5, 2024
1 parent 6d5d7c6 commit 1b0a799
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions motion-controller/example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
</a-assets>

<a-entity id="rig" position="0 0 2">
<a-entity motion-controller-space="hand: left; space: gripSpace" motion-controller-model="hand: left; overrideMaterial: hologram"></a-entity>
<a-entity motion-controller-space="hand: left; space: gripSpace" motion-controller-model="hand: left;"></a-entity>
<a-entity motion-controller-space="hand: left; space: targetRaySpace">
<a-box width="0.002" height="0.002" depth="2" color="red" position="0 0 -1"></a-box>
</a-entity>
<a-entity motion-controller-space="hand: right; space: gripSpace" motion-controller-model="hand: right; overrideMaterial: hologram"></a-entity>
<a-entity motion-controller-space="hand: right; space: gripSpace" motion-controller-model="hand: right;"></a-entity>
<a-entity motion-controller-space="hand: right; space: targetRaySpace">
<a-box width="0.002" height="0.002" depth="2" color="red" position="0 0 -1"></a-box>
</a-entity>
Expand Down
9 changes: 5 additions & 4 deletions motion-controller/src/motion-controller-model.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const MotionControllerModelComponent = AFRAME.registerComponent('motion-controll
}>().component({
schema: {
hand: { type: 'string', oneOf: ['left', 'right'], default: 'left' },
overrideMaterial: { type: 'string', oneOf: ['none', 'phong', 'occluder', 'hologram'], default: 'phong'},
overrideMaterial: { type: 'string', oneOf: ['none', 'phong', 'occluder'], default: 'phong'},
overrideHandMaterial: { type: 'string', oneOf: ['none', 'phong', 'occluder', 'hologram'], default: 'hologram'},
buttonTouchColor: { type: 'color', default: '#8AB' },
buttonPressColor: { type: 'color', default: '#2DF' }
},
Expand All @@ -46,6 +47,7 @@ const MotionControllerModelComponent = AFRAME.registerComponent('motion-controll
return;
}
this.el.setObject3D('mesh', gltf.scene);
const isHandModel = this.motionController.id === 'generic-hand';

// Traverse the mesh to change materials and extract references to hand joints
gltf.scene.traverse(child => {
Expand All @@ -54,8 +56,7 @@ const MotionControllerModelComponent = AFRAME.registerComponent('motion-controll
}

// Extract bones from skinned mesh (as these are likely hand joints)
// FIXME: Perhaps explicitly check that hand joints are expected in case a controller mesh is skinned?
if(child.type === 'SkinnedMesh') {
if(isHandModel && child.type === 'SkinnedMesh') {
const skinnedMesh = child as THREE.SkinnedMesh;
const bones = skinnedMesh.skeleton.bones;
for(const bone of bones) {
Expand All @@ -72,7 +73,7 @@ const MotionControllerModelComponent = AFRAME.registerComponent('motion-controll
// The default materials might be physical based ones requiring an environment map
// for proper rendering. Since this isn't always desirable, convert to phong material instead.
const mesh = child as THREE.Mesh;
switch(this.data.overrideMaterial) {
switch(isHandModel ? this.data.overrideHandMaterial : this.data.overrideMaterial) {
case 'phong':
mesh.material = phongMaterialFromStandardMaterial(mesh.material as THREE.MeshStandardMaterial);
break;
Expand Down

0 comments on commit 1b0a799

Please sign in to comment.