Skip to content

Commit f2bf1cf

Browse files
vincentfretinclaude
andcommitted
Restore hover-sprite behavior in super-keyboard key color plane
The supermedium-sync in 8456119 dropped two pieces that are required for keyboards that ship a hover sprite (our `superkeyboard` model does — `keyboard-hover.png`): 1. Setting `src: hoverImg` on the color plane material (normal blending, sampled texture) instead of the additive-solid-color glow. 2. UV manipulation so the per-key plane samples only that key's region of the sprite. Since modern three.js replaced `geometry.faceVertexUvs` with BufferGeometry, switch to `texture.offset` + `texture.repeat` which gives the same result. Without this, the hover plane was drawn as a flat white (or `keyHoverColor`) rectangle on top of each key — an opaque white square with the letter erased behind it. The additive-glow path is preserved for keyboards without a hover sprite, and setAttribute declares `blending: 'additive'` directly instead of relying on a componentinitialized listener (which now fires synchronously and was being attached too late). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7069176 commit f2bf1cf

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/components/super-keyboard.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,25 @@ AFRAME.registerComponent('super-keyboard', {
264264
* The plane for visual feedback when a key is hovered or clicked
265265
*/
266266
initKeyColorPlane: function () {
267+
var kbdata = KEYBOARDS[this.data.model];
267268
var keyColorPlane = this.keyColorPlane = document.createElement('a-entity');
268269
keyColorPlane.classList.add('superKeyboardKeyColorPlane');
269270
keyColorPlane.object3D.position.z = 0.001;
270271
keyColorPlane.object3D.visible = false;
271272
keyColorPlane.setAttribute('geometry', {primitive: 'plane'});
272-
keyColorPlane.setAttribute('material', {shader: 'flat', color: this.data.keyBgColor,
273-
transparent: true});
274-
keyColorPlane.addEventListener('componentinitialized', function (evt) {
275-
if (evt.detail.name !== 'material') { return; }
276-
this.getObject3D('mesh').material.blending = THREE.AdditiveBlending;
277-
});
273+
var matAttr = {
274+
shader: 'flat',
275+
color: this.data.keyBgColor,
276+
transparent: true
277+
};
278+
if (kbdata.hoverImg) {
279+
// Keyboards that ship a hover sprite blend normally so each key's
280+
// highlight is sampled from the texture, not painted as a flat color.
281+
matAttr.src = this.data.imagePath + '/' + kbdata.hoverImg;
282+
} else {
283+
matAttr.blending = 'additive';
284+
}
285+
keyColorPlane.setAttribute('material', matAttr);
278286
this.el.appendChild(keyColorPlane);
279287
},
280288

@@ -307,7 +315,15 @@ AFRAME.registerComponent('super-keyboard', {
307315
keyColorPlane.object3D.position.x = kdata.x * w - w2 + keyw / 2;
308316
keyColorPlane.object3D.position.y = (1 - kdata.y) * h - h2 - keyh / 2;
309317
// Color.
310-
keyColorPlane.getObject3D('mesh').material.color.copy(color);
318+
var material = keyColorPlane.getObject3D('mesh').material;
319+
material.color.copy(color);
320+
// If the keyboard uses a hover sprite, offset/repeat the texture so
321+
// the plane samples only the hovered key's region instead of the
322+
// whole image squashed into the key rectangle.
323+
if (kbdata.hoverImg && material.map) {
324+
material.map.offset.set(kdata.x, 1 - kdata.y - kdata.h);
325+
material.map.repeat.set(kdata.w, kdata.h);
326+
}
311327
break;
312328
}
313329
keyColorPlane.object3D.visible = true;

0 commit comments

Comments
 (0)