@pmndrs/handle
Version:
framework agnostic expandable handle implementation for threejs
26 lines (25 loc) • 911 B
JavaScript
import { Color } from 'three';
export const handleXRayMaterialProperties = {
depthTest: false,
depthWrite: false,
fog: false,
toneMapped: false,
transparent: true,
};
export function setupHandlesContextHoverMaterial(context, material, tag, { color, hoverColor, hoverOpacity, opacity, disabled = false, }) {
if ((hoverColor == null && hoverOpacity == null) || disabled) {
material.color.set(color);
material.opacity = opacity ?? 1;
if (disabled) {
material.opacity *= 0.5;
material.color.lerp(new Color(1, 1, 1), 0.5);
}
return;
}
hoverColor ??= color;
return context.subscribeHover((tags) => {
const isHovered = tags.some((activeTag) => activeTag.includes(tag));
material.color.set(isHovered ? hoverColor : color);
material.opacity = (isHovered ? hoverOpacity : opacity) ?? 1;
});
}