Skip to content
Snippets Groups Projects
hover-visuals.js 1.33 KiB
Newer Older
Brian Peiris's avatar
Brian Peiris committed
const interactorTransform = [];

Brian Peiris's avatar
Brian Peiris committed
 * Applies effects to a hoverer based on hover state.
 * @namespace interactables
 * @component hover-visuals
 */
AFRAME.registerComponent("hover-visuals", {
  schema: {
    hand: { type: "string" },
    controller: { type: "selector" }
  },
Brian Peiris's avatar
Brian Peiris committed
  init() {
    // uniforms are set from the component responsible for loading the mesh.
    this.uniforms = null;
  },
  remove() {
Brian Peiris's avatar
Brian Peiris committed
    this.uniforms = null;
Brian Peiris's avatar
Brian Peiris committed
    if (!this.uniforms || !this.uniforms.size) return;
Brian Peiris's avatar
Brian Peiris committed
    this.el.object3D.matrixWorld.toArray(interactorTransform);
    const hovering = this.data.controller.components["super-hands"].state.has("hover-start");
Brian Peiris's avatar
Brian Peiris committed
    for (const uniform of this.uniforms.values()) {
      if (this.data.hand === "left") {
        uniform.hubs_HighlightInteractorOne.value = hovering;
        uniform.hubs_InteractorOnePos.value[0] = interactorTransform[12];
        uniform.hubs_InteractorOnePos.value[1] = interactorTransform[13];
        uniform.hubs_InteractorOnePos.value[2] = interactorTransform[14];
      } else {
        uniform.hubs_HighlightInteractorTwo.value = hovering;
        uniform.hubs_InteractorTwoPos.value[0] = interactorTransform[12];
        uniform.hubs_InteractorTwoPos.value[1] = interactorTransform[13];
        uniform.hubs_InteractorTwoPos.value[2] = interactorTransform[14];