Skip to content

Commit

Permalink
Update opacity/muting status
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpolarzero committed Dec 27, 2022
1 parent 48a5199 commit 1a2a38f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/World/Audio/components/AudioControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ const AudioControls = () => {
}),
}),

// TODO voice enable/disable
'Voice (VX)': folder({
'Enable voice': {
value: audioParams.isVxEnabled,
onChange: (value) => audioParams.setIsVxEnabled(value),
},
}),
});

return null;
Expand Down
39 changes: 29 additions & 10 deletions src/World/Audio/components/AudioSphere.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useAtmoky from '../../../stores/Atmoky';

Globals.assign({ frameLoop: 'always' });

// ! Is click disabled when opacity 0 ?
// ! add isVxEnabled in Interactive and don't set hovered if disabled

const AudioSphere = ({ audio, info, analyser }) => {
const [isMuted, setIsMuted] = useState(false);
Expand All @@ -20,7 +20,7 @@ const AudioSphere = ({ audio, info, analyser }) => {
const ref = useRef();
const rotationSpeed = useMemo(() => Math.random() - 0.5, []);

const { scale, color } = useSpring({
const { scale } = useSpring({
scale:
hovered[0] && hovered[0].id === info.id
? isMuted
Expand All @@ -29,12 +29,17 @@ const AudioSphere = ({ audio, info, analyser }) => {
: isMuted
? 0.5
: 1 + gain,
color: isMuted ? '#ffffff' : analyser.color,
config: config.wobbly,
});

const { opacity } = useSpring({
opacity: isMuted ? 0.1 : 1,
});

const handleClick = async (e) => {
e.stopPropagation();
if (isDisabled) return;

setIsMuted(!isMuted);
toggleMuteSource(audio, info.id);
};
Expand All @@ -54,8 +59,17 @@ const AudioSphere = ({ audio, info, analyser }) => {

// Enable/disable voice
useEffect(() => {
if (info.type === 'vx')
isVxEnabled ? setIsDisabled(false) : setIsDisabled(true);
if (info.type === 'vx') {
if (isVxEnabled) {
setIsDisabled(false);
audio.setGainLinear(1);
ref.current.material.opacity = 1;
} else {
setIsDisabled(true);
audio.setGainLinear(0);
ref.current.material.opacity = 0.1;
}
}
}, [isVxEnabled]);

// Disable console warning for the animated.mesh
Expand All @@ -71,10 +85,10 @@ const AudioSphere = ({ audio, info, analyser }) => {
<animated.mesh ref={ref} onClick={handleClick} scale={scale}>
<sphereGeometry args={[1, 32, 32]} />
<animated.meshStandardMaterial
color={color}
wireframe={!isMuted}
transparent={isDisabled}
opacity={isDisabled ? 0 : 1}
color={analyser.color}
wireframe
transparent
opacity={opacity}
/>
</animated.mesh>
<DREI.Html
Expand All @@ -88,7 +102,12 @@ const AudioSphere = ({ audio, info, analyser }) => {
textTransform: 'uppercase',
textAlign: 'center',
color: 'white',
opacity: hovered[0] && hovered[0].id === info.id ? 1 : 0.1,
opacity:
hovered[0] && hovered[0].id === info.id
? 1
: info.type === 'vx' && !isVxEnabled
? 0
: 0.1,
transition: 'opacity 0.3s',
}}
>
Expand Down
5 changes: 4 additions & 1 deletion src/stores/Atmoky.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export default create((set, get) => ({
},
// Voice
isVxEnabled: true,
setIsVxEnabled: (isVxEnabled) => set((state) => ({ isVxEnabled })),
setIsVxEnabled: (isVxEnabled) => {
console.log(isVxEnabled);
set((state) => ({ isVxEnabled }));
},

/**
* Listener
Expand Down

1 comment on commit 1a2a38f

@vercel
Copy link

@vercel vercel bot commented on 1a2a38f Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

metaverse – ./

metaverse-git-main-polar0.vercel.app
metaverse-polar0.vercel.app
metaverse-tau-two.vercel.app

Please sign in to comment.