Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
react-spring/three not working for mesh color

I am trying to add a color transition for my mesh but am unable to do so with react-spring

Scene.js

import { useSpring, animated } from '@react-spring/three'

const Cell = () => {
  const [hovered, hover] = useState(false);
  const springs = useSpring({ color: hovered ? 'hotpink' : 'orange'})

  <animated.mesh
   onPointerEnter={(e) => {
        e.stopPropagation();
        hover(true);
      }}
      onPointerLeave={(e) => {
        e.stopPropagation();
        hover(false);
      }}
   >
    <planeGeometry args={[1, 1, 1]} />
    <meshBasicMaterial color={springs.color} />
  </animated.mesh
}

This just leaves my mesh with a white/grey color.

In the example provided here they used it in a similar way and I am unsure why it does not work. I have tested this by changed scale on the mesh itself and it worked then.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

SpringValues can only be applied to animated components. You have three components there, mesh, planeGeometry and meshBasicMaterial. You've animated mesh but you're not applying SpringValues to it so that's redundant.

Because you want the meshBasicMaterial to handle the SpringValue you should write it like so:

const Cell = () => {
  const [hovered, hover] = useState(false);
  const springs = useSpring({ color: hovered ? 'hotpink' : 'orange'})

  return <mesh
   onPointerEnter={(e) => {
        e.stopPropagation();
        hover(true);
      }}
      onPointerLeave={(e) => {
        e.stopPropagation();
        hover(false);
      }}
   >
    <planeGeometry args={[1, 1, 1]} />
    <animated.meshBasicMaterial color={springs.color} />
  </animated.mesh
}

You can see this working here – https://codesandbox.io/s/react-spring-forked-6qgre?file=/src/App.js

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda